textbox focus out
I need to focus out from the textbox when it focus in.
I try to set focus for outer div and its working fine in IE but not in mozilla.
How do I do this?
This is my current code:
<div id="outer"> <input type =开发者_Python百科 "textbox" /></div> Onfocus: document.getElementById("outer").focus()
I wonder what's the purpose of using a textbox in this case if the user can never write anything inside. Just add a disabled="disabled"
attribute or readonly="readonly"
(in case you want to post the value).
In HTML:
<input type="text" onfocus="this.blur();" />
In JS:
document.getElementById("input1").onfocus = function () { this.blur(); }
Some elements cannot accept focus without being editable.
Where is the point in that? JS would be (didn't test it):
$('#textbox').focusin(function() {
$(this).focusout();
});
I have tried all the answers and not worked in all the browsers. And I combined all together in to it.
TextBox.readonly = true;
OnFocus:
var curText = TextBox.value;
TextBox.value = "";
TextBox.value = curText;
TextBox.blur();
TextBox_Parent.focus()
And its working fine in all the browsers
/*for textarea*/
$(document).ready(function() {
$('textarea[type="text"]').addClass("idleField");
$('textarea[type="text"]').focus(function() {
$(this).removeClass("idleField").addClass("focusField");
if (this.value == this.defaultValue){
this.value = '';
}
if(this.value != this.defaultValue){
this.select();
}
});
$('textarea[type="text"]').blur(function() {
$(this).removeClass("focusField").addClass("idleField");
if ($.trim(this.value == '')){
this.value = (this.defaultValue ? this.defaultValue : '');
}
});
});
that's what I used on my form.
精彩评论