javascript - 操作 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>
解决方案
你试过val
吗?,它只能在同一个域链接上工作!
$('#test').contents().find('#text').val('WELCOME');
请确保将 javascript 放在之后iframe
或将其放在onload
从iframe
谢谢 :)
推荐阅读
- spring-boot - p:ajax 请求期间未显示 ViewExpiredException 的错误页面
- join - NestJS / TypeORM 连接来自两个不同数据库的两个表
- python - 如何将字典的键值从随机数更改为连续整数?
- c++ - 使用 C++ 时如何添加带空格的名称?
- javascript - 基于选择多选下拉显示和隐藏的Angular-6无法正常工作
- javascript - 如何在 nuxt 中为 dotenv 设置自定义路径
- matlab - matlab中三角格的邻接矩阵
- android - 我们可以在android中自定义WebView吗
- html - 未在 Angular Material Table 上选择元素时返回 false
- php - 什么时候全局函数不是可调用的?