js实现输入框仿html5 placeholder功能

本文介绍了如何使用JavaScript模拟HTML5的placeholder功能。通过将label定位在输入框上方,并根据输入内容动态显示或隐藏label,为不支持placeholder的浏览器提供类似体验。提供了一段可以直接运行的代码示例。
摘要由CSDN通过智能技术生成

思路是将label定位到输入框上面,根据输入框内容判断显示或者隐藏label,当然如果浏览器支持html5则就使用placeholder功能就ok了,所以可以预先判断一下是否支持。方法很简单,下面代码直接运行可以实现效果。


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <script type="text/javascript" src="jquery-1.8.2.js"></script>
  <style type="text/css">
	ul,li{list-style:none;margin:5px 0px;padding:0px;}
	.label-text-tips{margin-bottom:-30px;float:left;color:black;height:25px;line-height:20px;color:#ccc;}
	.txt-mobile{position:relative;z-index:22;background-color:transparent;border:solid 1px #ccc;}
  </style>
  <script type="text/javascript">
  <!--
	$(document).ready(function(){
	    if (!IsPlaceholderSupport())
	    {
			CopyPlaceholder("la","txt_mobile"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值