我有以下
<div class="change">a</div>
<div class="keep">b</div>
<div class="change">c</div>
<div class="change">d</div>
<div class="keep">e</div>
<div class="change">f</div>
我需要一个jQuery语句来使class="change"
的所有元素都为大写。
答案 0 :(得分:1)
试试这个:
$(document).ready(function() {
$(".change").each(function(){
var str = $(this).text().toUpperCase();
$(this).text(str);
})
})
&#13;
<div class="change">a</div>
<div class="keep">b</div>
<div class="change">c</div>
<div class="change">d</div>
<div class="keep">e</div>
<div class="change">f</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
&#13;
答案 1 :(得分:0)
Why do you need jquery for this, You can easily do it with css.
.change {
text-transform: uppercase;
}
<div class="change">a</div>
<div class="keep">b</div>
<div class="change">c</div>
<div class="change">d</div>
<div class="keep">e</div>
<div class="change">f</div>