閒的蛋疼,演示一下Jquery插件placeholder的用法,藉助該插件可以輕鬆實現HTML5中placeholder特效:javascript
效果圖:css
實現代碼:
html
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>藉助jquery placeholder實現HTML5中placeholder特效</title> <script type="text/javascript" src="<%=basePath%>js/jquery-1.8.3.min.js"></script> <script type="text/javascript" src="<%=basePath%>js/jquery.placeholder.js"></script> <script type="text/javascript"> $(function() { $('input, textarea').placeholder(); }); </script> <style type="text/css"> input, textarea { font-family: Helvetica, Arial; color: #000;} .placeholder {color: #aaa;} </style> </head> <body> <center style="margin-top: 10%"><font style="font-size: 18pt; font-weight: bold;font-weight: bold; color: red;">藉助jquery placeholder實現HTML5中placeholder特效</font></center><br><br> <input type="text" id="userName" name="userName" placeholder="請輸入username…" style="margin-bottom: 12px;"><br> <input type="password" id="password" name="password" placeholder="請輸入密碼…" style="margin-bottom: 12px;"><br> <textarea id="personalInformation" name="personalInformation" rows="3" cols="50" maxlength="200" placeholder="請輸入我的信息…"></textarea> </body> </html>
說明:上面樣例並不是HTML5頁面,但由於使用了該插件因此看上去和HTML5的效果差點兒相同;上面樣例使用了jquery-1.8.3.min.js和jquery.placeholder.js兩個文件,這兩個文件可在如下的下載資源中找到。java
【0分下載資源】jquery