Detect character in div and remove it Javascript or jQuery
I have this div:
<h1>$340</h1>
I need to detect if inside of this div there is a dollar symbol,
If so - remove it
I'll explain again: I have got this code so far so I manage to detect if the symbol is in the div, but I can't figure how to remove it and update the DOM?
var sign = $('h1').text();
if (sign.indexOf("$") >= 0) {
//remove the sign
}
使用简单的正则表达式很容易
var div = $('your selector here');
div.html(div.html().replace(/$/g, ''));
这就是我的意思,没有If条件:
$('h1').text( $('h1').text().replace("$", ''));
像这样尝试
var price = $("h1").html().replace(/[^d.]/g, '');
console.log(price);
链接地址: http://www.djcxy.com/p/74100.html