Heim  >  Artikel  >  Web-Frontend  >  用JS操作FRAME中的IFRAME及其内容的实现代码_javascript技巧

用JS操作FRAME中的IFRAME及其内容的实现代码_javascript技巧

WBOY
WBOYOriginal
2016-05-16 19:02:29989Durchsuche

问:想通过在地址栏输入一段JS来设置一下页面里某个FRAME中的IFRAME的URL和里面某个TEXT的值,然后点击提交按钮。注意:页面是其它网站的,不要给出一些改动页面代码的答案。具体情况如下:

主页面.htm:

view plaincopy to clipboardprint?

           

          main.jsp :  



  

要求: 

1.当打开主页面后,在地址栏里输入一段JS,来改变mainFrame的src为http://.../c.jsp. 

2.当打开主页面后,在地址栏里输入一段JS,来设置mainFrame此时的页面中name为"txt1"的文本框的值为"119",并点击其中name为"btn1"的按钮. 

GOOGLE了一下,还真没找到现成的类似答案。于是自己试了试,试出了答案。相信对于再问同样问题的朋友,可以有所帮助。

1.javascript:frames("primaryFrame").document.mainFrame.location=http://.../c.jsp;   

2.javascript:var a=frames("primaryFrame").document.mainFrame.document.getElementById("txt1").value="119";frames("primaryFrame").document.mainFrame.document.getElementById("btn1").click();

至于设置文本框为什么是var a=frames("primaryFrame").document.mainFrame.document.getElementById("txt1").value="119";而不是直接用frames("primaryFrame").document.mainFrame.document.getElementById("txt1").value="119"; 大家试试就知道了。
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn