<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
function regexp_test(input){
var reg=/^(?!.*[%\'\"?])/g
alert(reg.test(input))
}
</script>
</HEAD>
<BODY>
<input type="textbox" id="txt1" name="txt1"/>
<input type="button" id="btn1" name="btn1" value="Click" onclick="javascript:regexp_test(txt1.value)"/>
</BODY>
</HTML>
工作中经常遇到字符串中含有"",由于js动态创建div元素,如果title中含有"",就会出现莫名的错误,由此记录下此bug。 var question = 是否经常感到"压力"或其他。 var newQuestion = question.replace(/\"/g, "-") //把 双引号用-代替 ,当然也可以""代替,表示去除。//检测某字符串中是否包含特殊字符 function special( str ){ var special = RegExp(/[(\ )(\~)(\!)(\@)(\#) (\$)(\%)(\^)(\&)(\*)(\()(\))(\-)(\_)(\+)(\=) (\[)(\])(\{)(\})(\|)(\\)(\)(\:)(\')(\")(\,)(\.)(\/) (\<)(\>)(\?)(\)]+/) return ( special.test(str) ) } 返回true说明有特殊符号。