onclick(this.value)代碼詳解
<html> <head> <script language="javascript"> function test(value){ if(value=='1') { alert("11111111"); }else{ alert("00000000"); } } </script> </head> <body> <form name="form1" method="post" action=""> <input type="radio" name="ra" value="1" onclick="test(this.value)"/> 個人 <input type="radio" name="ra" value="0" onclick="test(this.value)""/> 公司 </form> </body> </html>
2.onclick(this)代碼詳解
一般標簽中會使用href和onclick兩種方式來進行進行頁面跳轉或執行動作,但是小編一般都會使用onclick來進行執行Ajax函數進行跳轉,並同時使用onclick=”xxxxxx(this)”來傳遞動態參數:例子如下
JSP代碼如下:
<a href="javascript:void(0);" onclick="xxxx(this)" userId=${userId}>${userName}></a>
Js代碼如下:
function xxxx(obj) { var thisObj=$(obj);//js對象轉jquery對象 var userId=thsiObj.attr("userId"); alert(userId); }
一般會將href寫為“javascript:void(0)” 而不是“#”,因為可以防止不必要的頁面跳動;
而this指的就是a標簽這個對象