当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jquery实现搜索框常见效果的方法教程

jquery实现搜索框常见效果的方法教程

2019年03月31日  | 移动技术网IT编程  | 我要评论

本文实例讲述了jquery实现搜索框常见效果的方法。分享给大家供大家参考。具体实现方法如下:

代码如下:


<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>jquery搜索框效果</title>
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript">
 $(function(){
  var searchbox = $("#search");
  searchbox.focus(function(){
   if(searchbox.val() == this.title){
    searchbox.val("").css({'font-style':'normal','color':'#000'});
   }
  });
  //光标离开搜索框时
  searchbox.blur(function(){
   if(searchbox.val() == ""){
    searchbox.val(this.title).css({'font-style':'italic','color':'#ccc'});
   }
  });
  searchbox.blur();
 });
</script>
</head>
<body>
<input id="search" type="text" title="search" value="" /><input type="submit" value="搜索" />
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网