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).
I've added a focus
and blur
so when i focus
on the textfield
, the default text dispersers. And on blur
, it comes back. But it's not working, even tho its working on the test i made first.
Hers the 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
-Ty for kicking me in the head ;)
on the focus within the condition body, you have forgotten the class selector.
use
$(".ringenven").val("");
instead of
$("ringenven").val("");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.