【问题标题】:Adding title to dynamically generated iframe为动态生成的 iframe 添加标题
【发布时间】:2017-08-29 20:21:12
【问题描述】:

我正在动态生成 iframe 并为其添加标题,但我将操作方法​​名称作为标题而不是给定的标题。我的代码是:

("#modalBody").empty().append('<iframe title="This is the title" id="iframeID"></iframe>');
$("#iframeID").attr("src", "../Employee/GetEmployeeDetails?empID=" + empID);
$('#empModal').modal('show');

标题为:GetEmployeeDetails 而不是 'This is the title'

任何帮助将不胜感激。谢谢。

编辑: 我发现了一个类似的问题,但这里 iframe 是动态生成的,而在该问题中 iframe 不是动态生成的。

编辑 -2 这也给出了相同的结果:

 ("#modalBody").empty().append('<iframe title="This is the title" id="iframeID"></iframe>');
    $("#modalBody iframe").contentDocument.title = 'My New title!';
 $("#iframeID").attr("src", "../Employee/GetEmployeeDetails?empID=" + empID); $('#empModal').modal('show');

【问题讨论】:

  • @Xiaoy312 是的,我在发布问题之前已经看到了那个问题,这个问题有点不同,这里我动态生成 iframe。我试过但无法解决问题。 :)
  • 对不起,为什么是 iframe?

标签: c# jquery asp.net-mvc-4 iframe


【解决方案1】:

我似乎无法复制您发布的内容,但以下标记对我有用:

HTML

<div id="modalBody">
  <div id="somemarkuphere">

  </div>
</div>

JS

$(document).ready(function() {
  $("#modalBody").html('<iframe title="This is the title" id="iframeID"></iframe>');
   $("#modalBody iframe").attr("src", "../Employee/GetEmployeeDetails?empID=" + 1);
  $("#modalBody iframe").attr("title", 'My New title!');
});

https://jsfiddle.net/o2gxgz9r/12781/

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 2015-06-26
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 2011-01-30
    • 1970-01-01
    相关资源
    最近更新 更多