jQuery each循环错误在哪里哦?_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 09:28:42
Original
967 people have browsed it

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD>  <TITLE> New Document </TITLE>  <META NAME="Generator" CONTENT="EditPlus">  <META NAME="Author" CONTENT="">  <META NAME="Keywords" CONTENT="">  <META NAME="Description" CONTENT=""><script src="jquery-1.8.0.js"></script> </HEAD> <BODY>  <TABLE width="35%" height="160"border="0" align="center">  <TR>		<TD height="32" colspan="2" align="center">用户登录</TD>  </TR>  <TR>	<TD width="29%" height="36">登录名称</TD>	<TD width="71%"><input class="text" type="text"/></TD>  </TR>  <TR>	<TD height="38">登录密码</TD>	<TD><input class="text" type="password"/></TD>  </TR>  <TR>	<TD colspan="2" align="center">		<input type="submit" id="btn" value="登录" onclick="check()"/>	</TD>	<TD></TD>  </TR>  </TABLE> </BODY></HTML><script>	$("#btn").click(		function()		{			$(".text").each(				function()				{					if($(this).val()=="")					{						alert("所有的文本框都必须填写!");						return false;					}				}			)		})</script>
Copy after login


回复讨论(解决方案)

你这写法本来就不对。js里面按照你写的意思,是给btn绑定一个click事件。页面上,你是直接调用check()方法。
要么你把页面上调用check去掉,然后绑定
$(function(){
$("#btn").bind('click',function(){
//do somethings
});
});
要不然就是调用check,写一个check方法
function check(){
//do somethings
}

click (   是个中文括号来的。

     这个好多余

验证是否为空或者内容不符,jquery有鼠标离开事件,还有就是$(document).ready(function(){})哪去了

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template