2010-02-03 17 views
3

我需要從文本集中了,當它集中在。文本框集中了

我嘗試設置焦點外層div並在其IE瀏覽器工作正常,但在Mozilla。

我該怎麼做?

這是我當前的代碼:

<div id="outer"> <input type = "textbox" /></div> Onfocus: document.getElementById("outer").focus() 
+0

任何代碼從你身邊? – 2010-02-03 12:19:56

+0

Onfoucs: 的document.getElementById( 「外」)專注() – Santhosh 2010-02-03 12:23:26

+0

請把這個變成你的問題。 – 2010-02-03 12:39:30

回答

1

我試過所有的答案,並沒有在所有的瀏覽器中工作。我把所有的東西結合在一起。

  1. TextBox.readonly = true;

的onfocus:

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

  • TextBox.blur();

  • TextBox_Parent.focus()
  • 及其在所有的瀏覽器工作正常

    5

    我不知道什麼是在這種情況下,用一個文本框,如果用戶不能裏面寫任何東西的目的。只需添加disabled="disabled"屬性或readonly="readonly"(如果您想要發佈該值)。

    1

    這點在哪裏? JS會(沒有測試):

    $('#textbox').focusin(function() { 
        $(this).focusout(); 
    }); 
    
    3

    在HTML:

    <input type="text" onfocus="this.blur();" /> 
    

    在JS:沒有被編輯

    document.getElementById("input1").onfocus = function() { this.blur(); } 
    

    一些元素不能接受焦點。

    0
    /*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 : ''); 
        } 
    }); 
    

    });

    這就是我在我的表單上使用的。