我在jQuery中有字符串,如:
<select id='orderlist-0' name='orderitems[0].orderitem.OrderItemId'></select>
<span class='field-validation-valid'
data-valmsg-for='orderitems[0].orderitem.OrderItemId'
data-valmsg-replace='true'></span>
现在我想用1替换[]中的所有0。哪种方法简单有效?
答案 0 :(得分:0)
试试这个
var s="your string here"
var result=s.replace(/0/g, '1');
答案 1 :(得分:0)
您可以使用正则表达式来搜索和替换字符串。
var str,
re;
str = "<select id='orderlist-0' name='orderitems[0].orderitem.OrderItemId'></select><span class='field-validation-valid' data-valmsg-for='orderitems[0].orderitem.OrderItemId' data-valmsg-replace='true'></span>";
re = /(\[)(0)(\])/g;
str = str.replace(re, '$11$3');