如何在iframe中动态传递值 [英] How to pass value dynamically in iframe
本文介绍了如何在iframe中动态传递值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是iframe的代码,
Here is the code of iframe,
<div id="map_canvas">
<iframe width="100%" height="380" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/?ie=UTF8&t=m&ll=37.09024,-95.712891&spn=26.535573,37.353516&z=4&output=embed"></iframe>
</div>
在这里我想要动态传递src的值
怎么可能?
here in this i want pass src's value dynamically
How is it possible?
推荐答案
嗨朋友,
按照我的想法,它是一个简单的JavaScript,可以为你做到这一点。例如(我还没有测试过,可能需要一些调试)
我正在使用这个例子的jQuery。
Hi Friend,
As per I think, it is a simple javascript which can do it for you. For example (I have not tested it, it may require some debugging)
I am using jQuery of this example.
( document )。ready( function (){
var url; // 您可以从ajax请求或表单等动态获取此URL
// 待办事项:使用您喜欢的任何方法使用有效网址填充网址的功能。
// 设置iframe的ID。让我们给出一个myframe的id
(document).ready(function(){ var url;//You can get this url dynamically from an ajax request or from a form etc // To Do : A function to populate url with a valid url from any method you prefer. // Set an ID for the iframe. Let us give that an id of myframe
(' #myframe')。attr( src,url);
})
('#myframe').attr("src", url); })
这是没有jQuery的答案
Here's an answer without jQuery
window.onload = function()
{
var url; //You can get this url dynamically from an ajax request or from a form etc
// To Do : A function to populate url with a valid url from any method you prefer.
// Set an ID for the iframe. Let us give that an id of myframe
document.getElementById("myframe").setAttribute("src", url);
}
我想,这个简单的代码可以帮助你..
I guess, this simple code will help you..
这篇关于如何在iframe中动态传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文