简体   繁体   English

通过选择框选项更改Iframe SRC

[英]Change Iframe SRC through select box Options

I would like to know, how can we change the SRC url for IFRAME through select box. 我想知道,我们如何通过选择框更改IFRAME的SRC网址。

we have a following code. 我们有以下代码。

HTML CODE HTML代码

<select name="sign" size="1">
<option value="-1" selected="selected">Select Signature</option><option value="4ff42886$1$YT2.BF2.$241VJYgpUpWPD7p1Wjq5E1">Link Building India</option> 
</select>

IFRAME CODE 框架代码

<iframe name="iframe2" src="signature.php?sign=" align="top" height="100%" width="95%" hspace="10" vspace="10" align="middle"></iframe>

I just want to update the src of Iframe2 according to the value of Select box like this 我只想根据这样的“选择”框的值更新Iframe2的src

Final code for IFRAME That to be change according to the select box. IFRAME的最终代码根据选择框进行更改。

<iframe name="iframe2" src="signature.php?sign=4ff42886$1$YT2.BF2.$241VJYgpUpWPD7p1Wjq5E1" align="top" height="100%" width="95%" hspace="10" vspace="10" align="middle"></iframe>

Thanks 谢谢

Gun

$("select").change(function(){ // put a ID to select tag
  var url = "signature.php?sign="+$(this).val();

  $("iframe").attr("src",url); 

});

You can have a template and use that to re-render your iframe each time? 您可以拥有一个模板,并使用该模板每次重新渲染iframe You can do that since you know the parent the iframe resides in, right? 您可以这样做,因为您知道iframe所在的父级,对吗?

Something like.. 就像是..

var iframeHTMLTemplate = '<iframe ... name="blah" src="@src" />

And while appending to DOM.. 并且在附加到DOM时

$("select").change(function(){ // put a ID to select tag
  var url = "signature.php?sign="+$(this).val();

  var myIframe = $(iframeHTMLTemplate.replace('@src', url));

  container.append(myIframe);

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM