javascript中怎样判断输入的内容不含有引号,如:"",",',

来源:百度知道 编辑:UC知道 时间:2024/09/13 03:53:21
javascript中判断输入的内容不含有引号,如:"",",',
indexOf("'")<0这个不管用

indexOf("\"")这样就解决了

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>不能包含" '</title>
<script>

function check() {
var str = document.getElementById("test").value;
alert(str);
var pt = /'||"/;
if (str.match(pt)) {
alert("不能包含\"或'");
}
}

</script>
</head>

<body>

<input type="text"