我有一个函数,如果单击页面上的多个项目中的任何一个,该函数就会运行。该函数有效,我只是想知道是否有更好的方法使用 ||
或类似的东西列出它。
这是我到目前为止所拥有的:
Init: function () {
$('#indian-marker a').click(Operations.ShowIndia);
$('#map-2 a').click(Operations.ShowIndia);
$('#details-marker a').click(Operations.ShowIndia);
},
ShowIndia: function () {
$('#map').css('background-image', 'url("../img/map-background-india.jpg")');
$('#map-return').show();
$('#india-box-link').toggle();
$('#global-box-link').toggle();
return false;
}
最佳答案
,
应该可以工作
Init: function () {
$('#indian-marker a, #map-2 a, #details-marker a').click(Operations.ShowIndia);
},
ShowIndia: function () {
$('#map').css('background-image', 'url("../img/map-background-india.jpg")');
$('#map-return').show();
$('#india-box-link').toggle();
$('#global-box-link').toggle();
return false;
}
您可以从 documentation 查看此示例
关于jquery - 一个函数具有多个触发器。查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8615141/