js 屏蔽form的onkeydown onkeyup onkeypress 的13按键后
textarea组件回车失效问题处理。。
?
<!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=utf-8" />
<title>首页</title>
<script language="javascript">
function insertData(obj,str){
?if (document.selection) {
??????? var sel = document.selection.createRange();
??????? sel.text = str;
??? } else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
??????? var startPos = obj.selectionStart,
??????????? endPos = obj.selectionEnd,
??????????? cursorPos = startPos,
??????????? tmpStr = obj.value;
??????? obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
??????? cursorPos += str.length;
??????? obj.selectionStart = obj.selectionEnd = cursorPos;
??? } else {
??????? obj.value += str;
??? }
}
function moveEnd(obj){
??? obj.focus();
??? var len = obj.value.length;
??? if (document.selection) {
??????? var sel = obj.createTextRange();
??????? sel.moveStart('character',len);
??????? sel.collapse();
??????? sel.select();
??? } else if (typeof obj.selectionStart == 'number' && typeof obj.selectionEnd == 'number') {
??????? obj.selectionStart = obj.selectionEnd = len;
??? }
}
</script>
</head>
<body>
开发当中.........
<form onkeydown="if(event.keyCode ==13) return false;" onkeyup="if(event.keyCode ==13) return false;" onkeypress="if(event.keyCode ==13) return false;">
<textarea name="aaa" id="aaa" onsumbit="return true;"? onkeydown="if(event.keyCode ==13) {insertData(this,'\n');};"></textarea>
</form>
</body>
</html>
?