How do I make load only on a button click?

后端 未结 3 1471

Friends, My issue is that my page is really slow to load, because all of the load simeltaneously. I am pulling an RSS feed that if you click on the \"article\" button it w

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-28 09:50

    Html:

    
    

    In your jQuery:

    $("button").click(function(){
        var iframe = $("#myiFrame");
        iframe.attr("src", iframe.data("src")); 
    });
    

    Or if you wanted to load ALL iframes when you click one button... make sure they all have a data-src="your.url" attribute, and then loop through like this:

    $("button").click(function(){
        $("iframe").each(function(){
            $(this).attr("src", $(this).data("src"));
        });
    });
    

提交回复
热议问题