Javascript 从link href更改iframe源

Javascript 从link href更改iframe源,javascript,jquery,Javascript,Jquery,我需要从 我的HTML: <a class='gotothis' href='http://puu.sh/666.png'>this Image</a> <button type="button">Click Me!</button> <iframe id="frameimg" src="" width="300" height="300"> </iframe> $('button').click( fu

我需要从

我的HTML:

<a class='gotothis' href='http://puu.sh/666.png'>this Image</a>
<button type="button">Click Me!</button>
<iframe id="frameimg" src="" width="300" height="300">
</iframe>


        $('button').click( function(event) {
            var clicked = $(this);
            $("#frameimg").attr("src", " .gotothis image is here, help '); // Here the problem
        });    

点击我!
$(“按钮”)。单击(函数(事件){
var clicked=$(这个);
$(“#frameimg”).attr(“src”,“.gotothis image在这里,help”);//这里是问题所在
});    

您使用双引号“打开字符串,但使用单引号”关闭字符串。使用两个双引号或两个单引号

$("#frameimg").attr("src", " .gotothis image is here, help "); // Here the problem
或者,如果您指的是希望动态读取gotothis uri的事实,那么您应该从gotothis元素中读取href属性:

$("#frameimg").attr("src", $('.gotothis').attr('href')); // Here there is no problem

您使用双引号“打开字符串,但使用单引号”关闭字符串。请使用两个双引号或两个单引号

$("#frameimg").attr("src", " .gotothis image is here, help "); // Here the problem
或者,如果您指的是希望动态读取gotothis uri的事实,那么您应该从gotothis元素中读取href属性:

$("#frameimg").attr("src", $('.gotothis').attr('href')); // Here there is no problem

事件顺序混乱。将锚URL加载到iframe中的正确代码:

$(window).load(function() {
    $('button').click( function(event) {
        var clicked = $(this);
        window.setTimeout(function() {
            $("#frameimg").attr("src", $(".gotothis").attr("href"));
        }, 1000);
    });
});

(使用可爱的猫:)

事件顺序混乱。将锚URL加载到iframe中的正确代码:

$(window).load(function() {
    $('button').click( function(event) {
        var clicked = $(this);
        window.setTimeout(function() {
            $("#frameimg").attr("src", $(".gotothis").attr("href"));
        }, 1000);
    });
});

(和一只可爱的猫在一起:)

你能更清楚地说明你想要什么吗?你能更清楚地说明你想要什么吗?事实上,下面几行的所有代码都突出显示了“thisastring”语法,这应该是一个提示。事实上,下面几行的所有代码都突出显示了“thisastring”“语法突出显示,应该是一个提示。