onkeydown事件里面写
如下,我简单写了一下:
htmlheadscript type=text/javascript function whichButton(obj, event) { var keycode = event.which || event.keyCode; //按下了right键 if (keycode == 39) { //如果光标的位置到了6,则按键不生效 if (getCursorPosition(obj) = 6) { return false; } } } //判断光标的索引 function getCursorPosition(obj) { var cursurPosition = -1; if (obj.selectionStart) { cursurPosition = obj.selectionStart; } else { var range = document.selection.createRange(); range.moveStart(character, -obj.value.length); cursurPosition = range.text.length; } return cursurPosition; }/script/headbody input type='text' value='123456abcd' οnkeydοwn=return whichButton(this,event)/body/html
取消
评论