我看过很多问题,但似乎没有一个能回答这个问题。我非常需要这个帮助。我在Magentogo上托管,所以无法访问核心文件,但是在jquery的帮助下,我想从我的商店隐藏。00。例如,我的代码是这样的。Rs.该项目的价格也是在HTML中无法粘贴为
<div class="price-block"
<p> The price of this item is
<span class="price" id="oldprice">
<span class="WebRupee"> Rs. </span>3,795.00 </span></p>
</span>
</div>
<script>
$('#price-block').html($('#price-block').html().replace(".00",""));
</script>
</body>
</html>
在div
中将它作为一个类<div class="price-block" // <-- also missing >
使用类选择器.
$('.price-block')
http://jsfiddle.net/WBsjA/我认为你需要循环每个.price-block
,而不是试图在整个代码垫子上运行它一次。
$('.price-block').each(function(){
$(this).html($(this).html().replace(".000","").replace(".00","").replace(".0",""));
});
你还需要修复你的HTML标记
<div class="price-block">
<p> The price of this item is
<span class="price" id="oldprice">
<span class="WebRupee"> Rs. 3,795.000</span>
</span>
</p>
</div>
http://jsfiddle.net/daCrosby/XK48G/这是一种方法。由于您的价格没有包装在它自己独特的HTML <span>
中,以便于定位和替换,因此您需要解析父元素,将子节点从文本节点中分离出来,并重新构建它:
var newval;
$('.price').each(function(j, pr) {
// trick to remove the webRupee element for later
var $webRupee = $(pr).find('.WebRupee').remove().wrap('<div>').parent().html();
$(pr).contents().each(function(i, el) {
if (el.nodeType === 3 && el.nodeValue.match(/.00/)) {
newval = el.nodeValue.replace(/.00/, '');
}
});
$(pr).html($webRupee + newval);
});
http://jsfiddle.net/mblase75/r2V6r/