1

我在使用 jquery 编辑模板中的文本时遇到问题,我似乎无法选择它。这是我所拥有的:

<div id="container">
<a class="teamLink smallButton" href="#">Click Here</a>
</div>

<script>
$('.smallButton a').text('new text');
</script>

我想编辑文本“单击此处”

4

2 回答 2

4

您的选择器会查找a属于 class 元素的后代的元素.smallButton

尝试这个:

$(document).ready(function() {
    $('a.smallButton').text('new text');
});

工作小提琴:http: //jsfiddle.net/9ntH6/

于 2013-08-14T17:45:34.080 回答
0

Jasons 解决方案应该有效。否则仅使用类选择器并更改 html

$('.smallButton').html('新文本');

于 2013-08-14T18:08:14.237 回答