onclick中,获取不了$(this),带参数

今天写项目,发现onclick中,$(this)默认绑定的是window对象,而不是当前点击对象。试了一下,onclick中,必须带this,在function内,才能获取当前对象。

原因:在html4中,onclick是全局时间属性。参考:http://www.w3school.com.cn/tags/html_ref_eventattributes.asp

所以,在事件中,添加this,返回触发事件的html元素

<a href="#" class="up" onClick="upward(this,1)">上移</a> <a href="#" class="down" onClick="downward(this,1)">下移</a></td></tr>

  

<a href="#" class="up" onClick="upward(this,2)">上移</a> <a href="#" class="down" onClick="downward(this,2)">下移</a></td></tr>

  

function upward(obj,x){
	var y;
        if(x == 1){
           y = $("#paramerIds");
	  }else if(x == 2)
{ y = $("#exParamerIds"); }
}

  

原文地址:https://www.cnblogs.com/person008/p/7247861.html