首页 > 解决方案 > 操作 iframe 的 ID 元素

问题描述

这里是检查我已将 iframe 附加到我的网站,并且我尝试了很多时间为 iframe 文本框赋予价值。但不起作用,有什么方法可以为 iframe 赋予价值。

我试过了

var test = $('#text').contents();

 test.value="WELCOME";

这是我的example.com/test/index.html

      <html>
  <head>
    <title>Test</title>
  </head>
  <body>
    <div>
        <label>Filed1
        <label>
           <textarea id="text"></textarea>
     </div>
      </body>
       </html>

我的 iframe:

   <iframe id ="test" width="350" height="400" 
   src="www.example.com/test/index.html" frameborder="1"  ></iframe>

标签: javascriptjquerygoogle-chrome-extension

解决方案


你试过val吗?,它只能在同一个域链接上工作

$('#test').contents().find('#text').val('WELCOME');

请确保将 javascript 放在之后iframe或将其放在onloadiframe

谢谢 :)


推荐阅读