hide cursor in textbox using javascript?
How to hide cursor i开发者_运维百科n asp.net textbox using JavaScript? I don't want see blink thing in textbox.
Please don't do this, you're breaking the user's expectations, the cursor is there for a reason, when the user types or hits delete, backspace, etc...they want to know where it's going to happen at.
If you want to edit a textbox and then cause focus to leave, that's a different matter, just focus another element:
document.getElementById("otherElement").focus();
Here's something you can try.
disclaimer -- as others have mentioned, it sounds like you're headed for an accessibility nightmare. You (or your client) still might have their reasons for wanting this behavior, though. This is a terrible hack, but it might give the results you want.
Hack
Have two text boxes, a real textbox that the user never sees but enters the text into and a dummy text box that displays the text. When the user clicks the dummy textbox, the real textbox should be focused. When the user edits the contents of the real textbox, the dummy textbox should be updated.
Example
Test it out here - http://jsbin.com/ihobe4/edit
function makeCaretInvisible(textboxId) {
var inputBox = document.getElementById(textboxId);
var outputBox = inputBox.cloneNode(true);
outputBox.id=outputBox.name='';
outputBox.onclick=function(){
inputBox.setSelectionRange(outputBox.selectionStart, outputBox.selectionEnd);
};
inputBox.onkeyup=function(){
outputBox.value=inputBox.value;
};
inputBox.style.position='absolute';
inputBox.style.top='-10000px';
inputBox.parentElement.insertBefore(outputBox, inputBox);
}
精彩评论