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>

  • 相关阅读:
    AWK 学习手札之一: an AWK tutorial
    SQL语句教程学习笔记之一
    c#支付宝支付
    table隔行变色
    读取接口
    倒计时
    新建的mvc项目运行之后报错找不到页面
    sql向表中添加字段
    取小数点后面几位数
    H5拨打电话
  • 原文地址:https://www.cnblogs.com/a1111/p/6540384.html
Copyright © 2011-2022 走看看