Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图提醒 regExp 的值new RegExp('(\\d)px','g');。正则表达式正在测试一个数字加“px”的变量。例如,如果你输入font -size: 14px; 我想提醒14px ;. 我很确定我没有正确执行此操作...
new RegExp('(\\d)px','g');
http://jsfiddle.net/6VgFc/
使用正则表达式/\d+px/g:
/\d+px/g
<script> function changeCode(){ var field = document.getElementById("fld"); alert(field.value.match(/\d+px/g)); } </script> <textarea id="fld"></textarea> <button id="btn" onclick="changeCode();">Get</button>
http://jsfiddle.net/6VgFc/2/