Javascript 用脚本替换部分文本
试着用折扣价来代替你们的价格,我做错了什么Javascript 用脚本替换部分文本,javascript,asp.net,Javascript,Asp.net,试着用折扣价来代替你们的价格,我做错了什么 <script type="text/javascript"> $(document).ready ( function() { $("td:contains('Your Price:')").text("Discount Price:"); } ); </script> $(文件)。就绪( 函数(){ $(“td:contains('您的价格:'))。文本(“折扣价格:”); }
<script type="text/javascript">
$(document).ready (
function() {
$("td:contains('Your Price:')").text("Discount Price:");
}
);
</script>
$(文件)。就绪(
函数(){
$(“td:contains('您的价格:'))。文本(“折扣价格:”);
}
);
谢谢 既然已经有了一个类,为什么还要用contains查找它呢
<div id="ctl00_MainContentPlaceHolder_YourPriceDiv" class="yourprice">
Your Price: <span id="ctl00_MainContentPlaceHolder_YourPriceLabel">$959.20</span>
<span class="thcustom"><br />Free Shipping</span>
</div>
为什么不把“你的价格:”写在:
then$(“#lblPrice”).text(“折扣价:”)
这应该适用于该网站,只需将其包含在文档中即可
或
你能发布你的HTML吗?或者最好是一个演示吗?@AlexPeattie代码列在附在页面的链接中。该文本不在表格单元格中。$('.yourprice').HTML($('.yourprice').HTML().replace('your','Discount'));这比1行还要短。谢谢欧文,又短又甜。谢谢@epascarello,你的回答帮我解决了另一个问题:)
var elem = jQuery(".yourprice");
elem.html( elem.html().replace("Your Price:","Discount Price:") );
var pricetag = $('.yourprice').html().replace('Your','Discount');
$('.yourprice').html(pricetag);
$('.yourprice').html(($('.yourprice').html().replace('Your','Discount')));