禁止文本框輸入英文單引號

<script>
 function renc(obj, reg, inputStr)
 {
  var docSel = document.selection.createRange()
  if (docSel.parentElement().tagName != "INPUT") return false
  oSel = docSel.duplicate()
  oSel.text = ""
  var srcRange = obj.createTextRange()
  oSel.setEndPoint("StartToStart", srcRange)
  var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length)
  return reg.test(str)
 }
</script>
<input onkeypress ="return renc(this,/^[^']*$/,String.fromCharCode(event.keyCode))" onpaste="return renc(this,/^[^']*$/,window.clipboardData.getData('Text'))" ondrop="return renc(this,/^[^']*$/,event.dataTransfer.getData('Text'))">
posted @ 2010-11-25 15:29  你妹的sb  阅读(470)  评论(0编辑  收藏  举报
百度一下