如何让js在页面获得传值之前就监控事件?? 本帖最后由 ThisTimed 于 2014-02-27 16:37:01 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你判断下传递的值进行勾选,除非下注册的事件不就好了$(document).ready(function(){ $(".setcf").change(function(){ switch($(".setcf:checked").val()){ case "0": $("#condfield").hide(); $("#nextactive").show(); break; case "1": $("#nextactive").hide(); $("#condfield").show(); break; default: break; } });var s=location.search//获取url后面?的参数if(s.indexOf('1')!=-1)$(".setcf[value='1']").attr('checked',true).trigger('change'); }); 感谢解答。我是用Java后端,页面直接用EL取的,这怎么弄??<input class="setcf" type="radio" name="tab_wactive.havecondfield" value="1" <c:if test="${wa.havecondfield==1}">checked</c:if>>是<input class="setcf" type="radio" name="tab_wactive.havecondfield" value="0" <c:if test="${wa.havecondfield==0}">checked</c:if>>否 <html xmlns="http://www.w3.org/1999/xhtml"><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"><title>无标题文档</title><script type="text/javascript" src="jquery-1.4.2.min.js"></script></head><body><input type="checkbox" class="setcf" value="1" /> 选项一 是<input type="checkbox" class="setcf" value="0" /> 选项二 否<input type="checkbox" class="setcf" value="1" /> 选项三 是<a href="" id="nextactive">是显示</a><a href="" id="condfield" style='display:none'>是隐藏</a> <script type="text/javascript"> $(document).ready(function(){ $('[value]').click(function(){ //console.log($(this).val()); if($(this).val() == 1 && $(this).attr('checked')){ $("#condfield").hide(); $("#nextactive").show(); }else{ $("#condfield").show(); $("#nextactive").hide(); } }) }); </script></body></html> 服务器端设置过直接trigger触发下事件就好了$(document).ready(function(){ $(".setcf").change(function(){ switch($(".setcf:checked").val()){ case "0": $("#condfield").hide(); $("#nextactive").show(); break; case "1": $("#nextactive").hide(); $("#condfield").show(); break; default: break; } });$(".setcf:checked").trigger('change'); }); 怎么样传参添加obj属性? 请问JSP页面中能使用autocomplete控件吗? 获取表格中的值,并将值存入数据库 javascript在ie7中运行慢 firefox中弹出菜单的问题? 急!100分!如何去掉iframe横向滚动条 求一个导航菜单的代码,可以动态扩展的,谢谢 怎样显示日期相加后的时间? 为什么不会停留在本页??????????? Javascript 中如何判断一个元素(譬如checkbox)是否存在? jqgrid与ztree发生冲突---急求 js获取高度自适应DIV的高度问题
$(".setcf").change(function(){
switch($(".setcf:checked").val()){
case "0":
$("#condfield").hide();
$("#nextactive").show();
break;
case "1":
$("#nextactive").hide();
$("#condfield").show();
break;
default:
break;
}
});
var s=location.search//获取url后面?的参数
if(s.indexOf('1')!=-1)$(".setcf[value='1']").attr('checked',true).trigger('change');
});
<input class="setcf" type="radio" name="tab_wactive.havecondfield" value="0" <c:if test="${wa.havecondfield==0}">checked</c:if>>否
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>无标题文档</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
</head><body>
<input type="checkbox" class="setcf" value="1" /> 选项一 是
<input type="checkbox" class="setcf" value="0" /> 选项二 否
<input type="checkbox" class="setcf" value="1" /> 选项三 是
<a href="" id="nextactive">是显示</a>
<a href="" id="condfield" style='display:none'>是隐藏</a>
<script type="text/javascript">
$(document).ready(function(){
$('[value]').click(function(){
//console.log($(this).val());
if($(this).val() == 1 && $(this).attr('checked')){
$("#condfield").hide();
$("#nextactive").show();
}else{
$("#condfield").show();
$("#nextactive").hide();
}
})
});
</script>
</body></html>
$(".setcf").change(function(){
switch($(".setcf:checked").val()){
case "0":
$("#condfield").hide();
$("#nextactive").show();
break;
case "1":
$("#nextactive").hide();
$("#condfield").show();
break;
default:
break;
}
});
$(".setcf:checked").trigger('change');
});