我在 MVC 中有一个 View ,其中需要在运行时在 for 循环内创建 iframe。每个 iframe 都有不同的来源。请任何人都可以建议一个带有示例代码的解决方案。谢谢 我尝试了下面的代码,但它不起作用..
<div class="width_100" id="div3">
@{ for (int i = 0; i < datatable1.Rows.Count; i++)
{
<script type="text/javascript">
window.onload = function () {
var iframe = document.createElement('iframe');
iframe.frameBorder = 0;
iframe.width = "300px";
iframe.height = "250px";
iframe.id = "randomid";
iframe.setAttribute("@datatable1.Rows[i]["UploadTitle"].ToString()", "");
document.getElementById("div3").appendChild(iframe);
}
</script>
}
}
}
</div>
最佳答案
您根本不需要 Javascript。
相反,您可以编写常规 <iframe>
循环内 HTML 中的标记。
关于javascript - 如何在运行时在 MVC 循环中动态创建 IFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26493651/