jquery
2010-07-22 49 views 0 likes 
0

用下面的代码我可以选择所有的href的值,然后改变它们;如何选择和更改jQuery的onclick属性?

$("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> 

非常感谢你的所有,现已...

问候,
Kerbooo

+0

'.filter()'需要返回TRUE;减少集匹配元素。 – jAndy 2010-07-22 15:21:40

+0

像这样,它的工作原理没有给出错误 – Kerberos 2010-07-22 15:22:57

+0

@ Kerberos - 你应该使用'.each()'而不是'.filter()'来处理你正在做的事情,甚至'.attr('href',function(i ,href){});'。 – 2010-07-22 15:25:10

回答

0
attr_val = $("div").attr("onclick"); 

attr_val.split("=")[1]; 
相关问题