zoukankan      html  css  js  c++  java
  • JavaScript实现搜索框效果

    要求:搜索框获取焦点的时候如果里面的内容是“请输入关键字”,则清空,否则不清空
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    	<title>搜索文本框效果</title>
    	<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    	<script type="text/javascript">
    	//页面加载就获取焦点
    	function Focus(){
    		document.getElementById('text1').focus();
    	}
    	$(function(){
    		$("#text1").focus(function(){
    			$(this).select();
    			$(this).css("background-color","orange");
    			if(this.value=="请输入关键字!"){
    					this.value="";
    				}
    		})
    		$("#text1").blur(function(){
    			$(this).css("background-color","white");
    			if(this.value==""){
    
    				this.value="请输入关键字!";
    				}
    		})
    	})
    	</script>
    </head>
    <body onload="Focus();">
    	搜索:<input type="text" id="text1" value="请输入关键字!">
    </body>
    </html>

  • 相关阅读:
    client offset screen 的区别
    js中const,var,let区别
    jquery的选择器
    gulp
    JS 实现图片放大效果
    html单个标签实现跑马灯效果
    前端之HTML知识点整理
    各种纯css图标
    防止反复点击的思路
    .NET Memcached Client 扩展获取所有缓存Key
  • 原文地址:https://www.cnblogs.com/a1111/p/6540384.html
Copyright © 2011-2022 走看看