gpt4 book ai didi

jquery - Jquery 问题查找和替换内容

转载 作者:行者123 更新时间:2023-11-28 01:20:21 25 4
gpt4 key购买 nike

亲们, 处理一个简单的问题,即用类“reason”为每个 span 替换屏幕上的文本。我已经尝试过加载和就绪事件,但没有任何运气。我的页面看起来像这样:

<div class="sp-body">
<div>......</div>
<div>......</div>
<section>......</section>
<div>
<span class="reason ng-binding">Trying To Replace This Reason!!!</span>

</div>
.
.
.
.

到目前为止我尝试过的:
方法一:

jQuery(window).load(function(){
//alert("JQuery Version: " + jQuery.fn.jquery); //This alert works
jQuery(".reason").each(function() {
console.log("Found span class");
$(this).text("Replacing with this!!!!");
});
console.log("After.......................");
});

方法二:

jQuery(document).ready(function(){    
//alert("JQuery Version: " + jQuery.fn.jquery); //This alert works
jQuery(".reason").each(function() {
console.log("Found span class");
$(this).text("Replacing with this!!!!");
});
console.log("After.......................");
});

PS:页面是使用 JSF 和 AngularJS 生成的(我认为生成的 HTML 无关紧要)

最佳答案

对我来说很好用!确切的问题是什么?

$("span.reason").each(function(){

$(this).text("Replacing with this !");

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="sp-body">
<div>......</div>
<div>......</div>
<section>......</section>
<div>
<span class="reason ng-binding">Trying To Replace This Reason!!!</span>

</div>
<div>
<span class="reason ng-binding">Trying To Replace This Reason!!!</span>

</div>
<div>
<span class="reason ng-binding">Trying To Replace This Reason!!!</span>

</div>
<div>
<span class="reason ng-binding">Trying To Replace This Reason!!!</span>

</div>

关于jquery - Jquery 问题查找和替换内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51543155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com