在iframe中加载web后设置textarea val

时间:2014-04-03 18:24:48

标签: javascript jquery iframe

我已经使用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');
});

它在两方面都不起作用吗?

2 个答案:

答案 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");
});