常用js总结

通过radio来显示/隐藏一个div

<div id="ArbAcei" >		
	<br/>
		有无不良反应停药 
		<input type="radio" name="blfyty" value="y"/>有
		<input type="radio" name="blfyty" value="n" checked="true" />无
		
		<div id="ty_reason"  style="display:none">
		
			原因是<br>
			   <input type="checkbox" name="ty_reason" value="阿司匹林过敏"/>阿司匹林过敏 <br>
			   <input type="checkbox" name="ty_reason" value="胃溃疡"/>胃溃疡 <br>
			   <input type="checkbox" name="ty_reason" value="十二指肠溃疡"/>十二指肠溃疡<br>
			   <input type="checkbox" name="ty_reason" value="血小板减少"/>血小板减少<br>
			   <input type="checkbox" name="ty_reason" value="阿司匹林过敏"/>阿司匹林过敏<br>
			   其他: <input type="text" name="ty_reason_qt"> <br>
		</div>
</div>
引入的js
$(document).ready(function(){
	$("input[name='blfyty']").bind("click",function(){
		//停药原因
		radioEvent_ty_reason($(this));
	});  
});

function radioEvent_ty_reason(e){
	if("blfyty"==e.attr("name")){
		if("y"==e.val()){
			$("#ty_reason").attr("style","display:''");
		}else{
			$("#ty_reason").attr("style","display:none");
		}
	}
}
另外 

$("input[name='blfyty']") 是给所有name为blfyty的input加上一个事件

$(":radio") 是给所有type为radio的加上事件
然后我们在对应的函数里,加上e.attr("name") 就可以获得到底是那组radio被点击了
再另外 有$(":radio")自然就还有$(":checkbox")
请参见 http://www.w3school.com.cn/jquery/jquery_ref_selectors.asp


第二种获得radio的反应事件

<span style="white-space:pre">	</span> <div id="fyql" style="display:none">
	     运用阿司匹林后胃肠道反应强烈
	    <input type="radio" name="fyql" onclick="ty_reason_fyql(this);"  value="强烈"/>强烈 
	    <input type="radio" name="fyql" onclick="ty_reason_fyql(this);" value="不强烈"/>不强烈 <br>
	 </div>
	
	<div id="fyql_y" style="display:none">
	      <font color="red">请选择ADP受体拮抗剂 </font> 
	 </div>
js
	function ty_reason_fyql(e){
		if("强烈"==e.value){
		   $("#fyql_y").attr("style","display:''");
	    }else{  
	       $("#fyql_y").attr("style","display:none");
	    }
	}


对复选框中的某一个框 区分点击与取消事件

<div id="ty_reason"  style="display:none">										
原因是<br>
  <input type="checkbox" name="ty_reason" onclick="ty_reason_gm(this);"  value="阿司匹林过敏"/>阿司匹林过敏 <br>
  <input type="checkbox" name="ty_reason" value="胃溃疡"/>胃溃疡 <br>
  <input type="checkbox" name="ty_reason" value="十二指肠溃疡"/>十二指肠溃疡<br>
  <input type="checkbox" name="ty_reason" value="血小板减少"/>血小板减少<br>
  <input type="checkbox" name="ty_reason" value="阿司匹林过敏"/>阿司匹林过敏<br>
  其他: <input type="text" name="ty_reason_qt"> <br>
</div>
js
function ty_reason_gm(e){
	
	   if(e.checked){  
		   alert("yes")
	    }else{  
	    	alert("no");
	    }  
}
另外 结合
$(":checkbox").bind("click",function(){
		xx(this);   //这里这个this 指的是dom对象
	});  
function xx(e){
                        //这个$(e) 是获得封装的jquery对象
	if("ty_reason"==$(e).attr("name")){
			//checed 是dom对象的属性
		if(e.checked){  
			alert("我选了"+e.value)
		}else{
			alert("我取消了"+e.value)
		}
	}
}
就能给每个checkbox加上是否点击事件


若干组radio,只有有一组选了是,就如何如何

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
       <script src="js/jquery1.7.js"></script>
  </head>
  
  <body>
  <form action="">
是否存在以下不适合应用阿司匹林的情况<br>
胃肠道出血
<input type="radio" name="aspl" value="是" >  是
<input type="radio" name="aspl" value="否" >  否<br>


胃溃疡
<input type="radio" name="wky" value="是" >  是
<input type="radio" name="wky" value="否" >  否<br>


十二指肠溃疡
<input type="radio" name="sez" value="是" >  是
<input type="radio" name="sez" value="否" >  否<br>

<div id="yes" style="display:none">
根据医生评估患者病情给予用药,挽救患者生命为第一位
</div>
<div id="no" style="display:none">
立即给予阿司匹林300mg嚼服
</div>

  </form>

  </body>
  
<script type="text/javascript">
 $(function(){
  $(":radio").click(function(){
    check();
  });
 });
 
 function check(){
	  
	 var radiolist= $('input:radio:checked');
	 var show=true;
	 for(var i=0;i<radiolist.length;i++){
		 if(radiolist[i].value=='是'){
			 $("#yes").show();
			 $("#no").hide();
			 show=false;
		 }
	 }
	 if(show){
		 $("#no").show();
		 $("#yes").hide();
	 }
	 
 }
 
</script>
</html>


上面的效果是
以上任意选项为是,则根据医生评估患者病情给予用药,挽救患者生命为第一位
如果均为否,则应立即给予阿司匹林300mg嚼服


再另外 
var radiolist= $('input:radio.adp:checked');


这是什么意思?

选取class为app的已选的radio

form的提交

  <body>
<form id="form" method="post">
	   评估是否存在<br>
		          糖尿病肾损伤(GFR<60ml/min/1.73mm)
		    <input type="checkbox" name="x" ><br>
			左室功能受损
			 <input type="checkbox" name="x" ><br>
			之前行冠状动脉搭桥术
			 <input type="checkbox" name="x" ><br>
		    GRACE评分在109~140  
		     <input type="checkbox" name="x" ><br>
		     <input type="button" value="下一步" onclick="xx()" >
  </form>
            
  </body>



	 function xx() {
		var list=document.getElementsByTagName("input");
		var form=window.form;
		for(var i=0;i<list.length;i++){
			if(list[i].checked){
				form.action="modules/jxgxb/ycpci.jsp";
				form.submit();
				return;
			}
		}
		var k=0;
		for(var i=0;i<list.length-1;i++){
			if(!list[i].checked){
				k++;
			}
		}
		if(k==4){
			form.action="modules/jxgxb/ywzl.jsp";
			form.submit();
		}
		
	}

页面跳转方式

self.location.href="modules/jxgxb/ybcl_no.jsp";



你可能感兴趣的:(常用js总结)