因为checkbox,radio只要设置了checked属性,不管html里给真正属性值是什么,$attr("checked")拿到的都是checked,而JS是弱语言,判断时非undefined都会给真。所以只要有check属性,这里判断就会走if分支。1。静态变量方式:
<!--
实现select标签回显
--> 1<select name="curStatus" value="${curStatus}">
<option value="0">-请选择-</option>
<option value="1" <c:if test="${'1' eq curStatus}">selected</c:if> >男</option>
<option value="2" <c:if test="${'2' eq curStatus}">selected</c:if> >女</option>
</select> 12345678
2。动态方式:两个变量都来自后台
<c:set var="schoolid" value="${pageDataSchoolId}" scope="request"/>
<select name="schoolId" id="schoolId" style="width: 95%">
<option value="0">==请选择==</option>
<c:forEach items="${organizeList}" var="var" varStatus="vs">
<option value="${varname_code}" <c:if test="${varname_code==schoolid}">selected</c:if> > ${varname}</option>
</c:forEach>
</select><script language="javascript">
function check()
{
if(documentform1checkboxchecked==false) //如果表单1的复选框没被选中。则执行以下语句
{
alert("请选中复选框");
return false;
}
}
</script>
'首先定义一个JS函数,复选框的名称为checkbox
<form id="form1" name="form1" method="post" action="indexhtml" onsubmit="return check()"> '这是表单1 注意!必须调用一个函数 onsubmit="return check()"js中的
if(!documentgetElementById("boxcheck")checked){
改为
if($("input[type='checkbox']:checked")length==0){<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>mainhtml</title>
<style type="text/css">
divleft_topnext2 {
background: url(r1png) 0px 4px no-repeat;
height: 20px;
line-height: 20px;
}
divleft_topnext2 a {
padding-left: 16px;
}
</style>
<script type="text/javascript">
onload = function ()
{
var divs = documentgetElementsByTagName('div');
for ( var i = 0; i < divslength; i++)
{
var me = divs[i];
meclicked = 0;
if (meclassName == 'left_topnext2')
{
meonclick = function ()
{
mestylebackgroundImage = meclicked == 0 'url(r2png)' : 'url(r1png)';
meclicked = meclicked == 1 0 : 1;
}
}
}
}
</script>
</head>
<body>
<div class="left_topnext2">
<a href="#">专题报道</a>
</div>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)