我如何使用.load函数插入内容到不同的Div

How can i use .load function to insert content into different Div

本文关键字:Div 何使用 load 函数 插入      更新时间:2023-09-26

我是jQuery的新手,所以如果我的问题看起来很肤浅,我真诚的道歉。我想知道如何在一个div中使用按钮将内容放置在另一个div中,当使用jQuery单击任何一个按钮时。每个按钮当然会加载自己的内容在特定的div,我想改变。

Thank you in expected

这很简单:

$("#buttonA").on("click", function() {
    $("#theDiv").load("http://theUrl");
});
$("#buttonB").on("click", function() {
    $("#theDiv").load("http://theOtherUrl");
});

#buttonA, #buttonB, #theDiv替换为您特定的选择器

一个更好的方法是使用data属性:

<button class="link-btn" data-url="http://theUrl">load A</button>
<button class="link-btn" data-url="http://theOtherUrl">load B</button>

$(".link-btn").on("click", function() {
    $("#theDiv").load($(this).data("url"));
});

下面的jquery可以提供帮助

$('#buttonid').click(function(){
$('#div2id').load('page.html');
}

代码如下:

$('#yourDivId').load('content.html');   // Your content source