-1

我的网站上有以下代码。

<div class="address2"><div class="placeholder">Address 2</div></div>

如何使用 jQuery 来定位和更改它?

谢谢

4

5 回答 5

1

您也可以尝试其他方法,将您的脚本包装在一个 settimeout 中,这将在 2 秒后执行您的脚本。

setTimeout(function(){ $(".placeholder").html("<strong>Replace</strong> this text with the existing text"); },2000);

就个人而言,我更喜欢使用 .html 来更改 div 或 table 等元素中的所有内容,这很简单,因为如果您要使用 .text 那么添加的字符串将不会考虑 html 代码并将其添加为普通文本,例如。

$(".placeholder").html("<strong>Replace</strong> this text with the existing text");

将打印:将此文本替换为现有文本

$(".placeholder").text("<strong>Replace</strong> this text with the existing text");

Will print: <strong>Replace</strong> this text with the existing text
于 2013-11-04T06:48:02.743 回答
1

您可以执行以下操作:

将 jquery 添加到您的 html HEAD

然后用一些 jquery 代码创建一个脚本标签:

// .placeholder is the targeting div with the placeholder class
$(".placeholder").html("Replace this text with the existing text");
于 2013-11-04T05:45:40.270 回答
1
$('.placeholder').text('Look ma, a changed value');
于 2013-11-04T05:45:51.867 回答
0
$(".address2 .placeholder").html("new html content")
于 2013-11-04T05:47:00.440 回答
0

proabaly你正在寻找这样的东西

$('.placeholder').on('click',function(){
    alert('i am clicked');
})

使用这个你可以点击那个div

或者如果您想更改文本,您可以使用

$('.placeholder').text("新文本")

于 2013-11-04T05:47:19.230 回答