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

<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'))">

你可能感兴趣的:(文本框)