如何使用jquery选择和更改onclick属性?

如何使用jquery选择和更改onclick属性?,jquery,Jquery,使用下面的代码,我可以选择所有a href的值,然后更改它们 $("a").each(function(){ if (this.hostname == location.hostname){ var url = this.href; var qs = $.jqURL.get('qs'); if(url.indexOf('qs=') == -1 && (qs!= undefined && qs!= '')){ if (

使用下面的代码,我可以选择所有a href的值,然后更改它们

$("a").each(function(){
 if (this.hostname == location.hostname){
     var url = this.href;
     var qs = $.jqURL.get('qs');
     if(url.indexOf('qs=') == -1 && (qs!= undefined && qs!= '')){
        if (url.indexOf('?')>0){
            $(this).attr('href', url + '&qs='+ qs);

        }
        else
        {
            $(this).attr('href', url + '?qs='+ qs);

        }
    }
 }
})
我想像上面的代码一样应用onclick属性

<div onclick="window.location.href='http://www.domain.com'" style="cursor:pointer">Test</div>
测试
非常感谢大家,现在已经

问候,

Kerboo

.filter()
需要返回
true
以减少匹配元素集。这样,它可以在不提供error@Kerberos-您应该使用
.each()
而不是
.filter()
,甚至
.attr('href',function(i,href){})。我不明白你原来的问题。你是说你想给每个div添加一个onclick吗?好的,我用“each”修复了“filter”,谢谢。
attr_val = $("div").attr("onclick");

attr_val.split("=")[1];