Javascript - string.replace() not replacing ALL
Javascript - string.replace() not replacing ALL
我用它来插入一些字符串数据:
$("#edit_order #"+key).val(value.replace('+',' '));
但是,"+"的第二个实例不会替换为以下字符串:
123123123+APT+123
相反,我得到输出:
123123123 APT+123
使用:
value.replace(/'+/g, ' ')
g
是一个全局匹配标志,将导致替换匹配 +
的所有实例。
试试...
$("#edit_order #"+key).val(value.replace(/'+/g,' '));
要替换所有,必须将值"替换"定义为正则表达式。
这是一个jsFiddle
相关文章:
- Replacing $ .ajax?
- jQuery is not loaded
- AngularJS JSON not arriving php
- $rootScope not working
- reactRedux is not defined
- jQuery document.ready not working
- Javascript/Jquery Blob not showing Chrome PDF
- ReferenceError: not defined
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- Javascript getElementsByTagName not working?
- jQuery's trim()的前缀为not运算符
- Javascript - element.childNodes does not see an append.newch
- SemanticUI模态not onDeny/onApprove事件未激发
- WebkitTransform not fluent
- JQuery.val( ) not working
- Tomcat websocket is not working
- :not选择器不适用于ul类-备选方案
- Javascript JSON.parse not working
- JQuery not replacing html
- Javascript - string.replace() not replacing ALL