Home  >  Article  >  Web Front-end  >  jquery 语句如何合并?_html/css_WEB-ITnose

jquery 语句如何合并?_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-21 09:02:17905browse

$('li').click(function(){
var li_link=$(this).attr('_src');
if(li_link&&li_link!='undefined'){location.href=li_link;}
})
$('span').click(function(){
var li_link=$(this).attr('_src');
if(li_link&&li_link!='undefined'){location.href=li_link;}
})
$('div').click(function(){
var li_link=$(this).attr('_src');
if(li_link&&li_link!='undefined'){location.href=li_link;}
})


我应该如何合并这些语句?谢谢,把它变为一个。


回复讨论(解决方案)

$('div,li,span').click(function(){
var li_link=$(this).attr('_src');
if(li_link&&li_link!='undefined'){location.href=li_link;}
})

$('div,li,span').click(function(){
var li_link=$(this).attr('_src');
if(li_link&&li_link!='undefined'){location.href=li_link;}
})



原来可以这么用,涨知识了。。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn