javascript中onclick(this)用法和onclick(this.value)用法介绍

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标签这个对象

 
原文地址:https://www.cnblogs.com/lxwphp/p/9988261.html