开发者

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.

  1. TextBox.readonly = true;

OnFocus:

  1. var curText = TextBox.value; TextBox.value = ""; TextBox.value = curText;

  2. TextBox.blur();

  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜