伙计们,
处理一个简单的问题,即用类“ span
”为每个reason
替换屏幕上的文本。我已经尝试了加载和就绪事件,但没有任何运气。我的页面看起来像这样:
<div class="sp-body">
<div>......</div>
<div>......</div>
<section>......</section>
<div>
<span class="reason ng-binding">Trying To Replace This Reason!!!</span>
</div>
.
.
.
.
到目前为止,我已经尝试过:
方法1:
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.......................");
});
方法2:
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无关紧要)
答案 0 :(得分:0)
对我来说很好!确切的问题是什么?
$("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>