简体   繁体   English

jQuery-文本字段上的焦点和模糊不起作用

[英]JQuery - Focus and Blur on textfield don't work

So, I'm serious confused here. 所以,我在这里很困惑。 I have a textfield , which is used for Searching, and in that textfield , theres a default text(Search here). 我有一个textfield ,用于搜索,在该textfield ,有一个默认文本(在此处搜索)。

I've added a focus and blur so when i focus on the textfield , the default text dispersers. 我添加了focusblur因此当我focus放在textfield (默认文本分散器)上时。 And on blur , it comes back. blur ,它又回来了。 But it's not working, even tho its working on the test i made first. 但是它不起作用,即使它是我首先进行的测试的结果。

Hers the JS: 她的JS:

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
<link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" rel="stylesheet" />

<script>
var data = [
        {"label" : "NAME | MAIL | NR."},
        {"label" : "NAME | MAIL | NR."}

        ];

$(function() {

    $('#search_bar').autocomplete(
    {
        source:data
    });
});


</script>

<script>

var default_value = "Search Here";

$(".ringenven").focus(function() {
    if($(".ringenven").val() == default_value)
    {
        $("ringenven").val("");
    }
});

$(".ringenven").blur(function() {
    if($(".ringenven").val() == "")
    {
        $(".ringenven").val(default_value);
    }
});

</script>

Heres the textbox: 这是文本框:

<input class="ringenven" id="search_bar" style="MARGIN-TOP: 35px; MARGIN-LEFT: 10px; WIDTH: 300px; HEIGHT: 22px" type="text" size="9" value="Search Here" name="search_bar" />

why don't you just use the placeholder attribute – @hyxnat 为什么不只使用占位符属性– @hyxnat

-Ty for kicking me in the head ;) -Ty踢我的头;)

on the focus within the condition body, you have forgotten the class selector. 在条件主体内的焦点上,您忘记了类选择器。

use 采用

$(".ringenven").val("");

instead of 代替

$("ringenven").val("");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM