jquery获取input标签的默认值


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <script language="javascript"
   src="${pageContext.request.contextPath}/js/jquery-1.4.2.js"></script>
  <base href="<%=basePath%>">
  <script language="javascript">
 $(function() {
  $("#only").focus(function() {
   if ($(this).val() == $(this)[0].defaultValue) {
    $(this).val("");
   }
  });
  $("#only").blur(function() {
   if ($.trim($(this).val()) == "") {
    $(this).val($(this)[0].defaultValue);
   }
  });
 });
</script>
 </head>
 <body>
  单选框:
  <input type="text" id="only" value="用户邮箱/手机号/用户名">
  按钮:
  <input type="button" id="but" />
 </body>
</html>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM