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

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

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

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

  

  

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

你可能感兴趣的:(onclick中,获取不了$(this),带参数)