0
<html>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script> 
        $("div.block").each(index){
            this.text('Fill this writing of divs with the classname "block"')} 
</script>

<body>
        <div>Not here</div> 
        <div class='block'>replace me -- not working, why?</div> 
        <div>Not here</div> 
        <div class='block'>replace me -- not working, why?</div>
</body>

</html>
4

1 回答 1

4

您不需要使用每个 - 您可以在整个选择中调用 text 方法:

$("div.block").text('Fill this writing of divs with the classname "block"');

顺便说一句,你上面的问题是你使用不正确

$("div.block").each(function(index, el){
    $(el).text('Fill this writing of divs with the classname "block"');
}); 
于 2012-11-22T23:32:22.037 回答