Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 更改元素中的iframe内容_Jquery_Iframe - Fatal编程技术网

Jquery 更改元素中的iframe内容

Jquery 更改元素中的iframe内容,jquery,iframe,Jquery,Iframe,我尝试使用上面的代码来更改iframe中的内容,但它不起作用。除非我把警报(“”)位于$('#关键字框').contents().find(“#step12”).html('')之上 如果公正会生效。原因是什么,任何人都可以提供帮助?可能只是您需要等待iframe加载 由于这是我目前唯一能想到的事情,请尝试以下方法: $(document).ready(function () { $('#keywordframe').contents().find("#step12").html('')

我尝试使用上面的代码来更改iframe中的内容,但它不起作用。除非我把
警报(“”)
位于
$('#关键字框').contents().find(“#step12”).html('')之上


如果公正会生效。原因是什么,任何人都可以提供帮助?

可能只是您需要等待iframe加载

由于这是我目前唯一能想到的事情,请尝试以下方法:

$(document).ready(function () {
    $('#keywordframe').contents().find("#step12").html('');
    $('#keywordframe').contents().find("#step12").html('11');
    $('#keywordframe').contents().find("#step13").html('');
    $('#keywordframe').contents().find("#step13").html('12');
    $('#keywordframe').contents().find("#step14").html('');
    $('#keywordframe').contents().find("#step14").html('13');
    $('#keywordframe').contents().find("#step15").html('');
    $('#keywordframe').contents().find("#step15").html('14');
});

我不知道它是否能解决您的问题,但值得一试。

在这里工作正常。您是否验证了选择器的长度为1+而不是0?我这边不行。我把我的iframe内容像这样回复gordan:我不想放进去,因为每个html都有自己的价值
$(document).ready(function () {
    $('#keywordframe').load(function() {
        $('#keywordframe').contents().find("#step12").html('');
        $('#keywordframe').contents().find("#step12").html('11');
        $('#keywordframe').contents().find("#step13").html('');
        $('#keywordframe').contents().find("#step13").html('12');
        $('#keywordframe').contents().find("#step14").html('');
        $('#keywordframe').contents().find("#step14").html('13');
        $('#keywordframe').contents().find("#step15").html('');
        $('#keywordframe').contents().find("#step15").html('14');
    });
});