如何从文本框中删除焦点?

时间:2013-07-15 18:22:30

标签: javascript jquery css css3

当打开表单时,光标在文本框中等待帮助文本。所以发生了一些验证错误。因此我不想在打开表单时使用焦点,用户必须单击文本并键入文本。但是文本框中的光标没有任何onfocus事件。

if(!$.trim($("#productsTextArea1").val())){
        helpTip = "help string ....";
        $("#productsTextArea1").val(helpTip);
        $("#productsTextArea1").css("color","#999");
        $("#productsTextArea1").click(function(event){
            if($("#productsTextArea1").val().indexOf("Enter a return")>-1){
                $("#productsTextArea1").css("color","black").val("");
            }
        });
    } else {
         $("#productsTextArea1").blur();
    }

请告知......

JSFIDDLE

1 个答案:

答案 0 :(得分:10)

更新:

使用HTML5占位符属性,您不需要使用任何js。

    <textarea id="productsTextArea1" name="product" rows="5" 
placeholder="Some Hint Text is Placed Here"></textarea>

要在所有输入元素上禁用自动对焦,请使用此选项。

  $(function(){
        $('input').blur();
    });

要取消对特定元素的自动对焦,请传递元素ID,如下所示:

$(function(){
    $('input#someid').blur();
});
相关问题