【发布时间】:2015-05-28 05:29:25
【问题描述】:
如何使用jQuery 更改class 的text?
这里是html 代码:
<div class="box1">
<div class="box box-default">
<div class="box-header with-border">
<h3 class="box-title">Collapsable</h3>
<div class="box-tools pull-right">
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
</div><!-- /.box-tools -->
</div><!-- /.box-header -->
<div class="box-body" id="testBody">
The body of the box
</div><!-- /.box-body -->
</div><!-- /.box -->
</div>
<div class="box2">
<div class="box box-default">
<div class="box-header with-border">
<h3 class="box-title">Collapsable</h3>
<div class="box-tools pull-right">
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
</div><!-- /.box-tools -->
</div><!-- /.box-header -->
<div class="box-body" id="testBody">
The body of the box
</div><!-- /.box-body -->
</div><!-- /.box -->
</div>
如何将box1 和box2 box-title class text 更改为不同的值?
我指的是每个框的这行html代码:
<h3 class="box-title">Collapsable</h3>
这是我的代码:
$('.box1.box box-default.box-header with-border.box-title').text("Box 1 title");
$('.box2.box box-default.box-header with-border.box-title').text("Box 2 title");
文本没有变化,控制台中也没有显示错误。
提前致谢。
【问题讨论】:
标签: jquery html class text selector