我已经使用jquery将网页加载到iframe
中$("#frame").attr("src", "website"); //this website is **external** web!
我想在iframe中设置textarea的值,例如点击
$( "body" ).on( "click", "#button", function() {
document.getElementById('textareaID').value = 'new value';
$('textarea#textareaID').val('new value');
});
它在两方面都不起作用吗?
答案 0 :(得分:0)
为该帧命名并访问该帧中的元素window.frames [“framename”]。document.getElementById(“textareaID”)。value =“new value”;
答案 1 :(得分:0)
您可以使用jquery contents()和find()函数来检测iframe中的元素,然后更改dom:
$( "body" ).on( "click", "#button", function() {
$("#idOfYourIframe").contents().find("#textareaID").val("NEW VALUE");
});