我有以下的地方,如果你点击其中一个列表项,JavaScript函数将被调用。这应该运行下面的jQuery来隐藏/显示一个元素。如何在jQuery中声明函数?
div#user-box
ul
li#dashboard(href="javascript:showonlyone('newboxes1')")
a Dashboard
li#settings(href="javascript:showonlyone('newboxes2')")
a Settings
div(class='newboxes' id='newboxes1')
p Dashboard
div(class='newboxes' id='newboxes2')
p Account ID:
我尝试这样做,但它没有工作:
$(document).ready(function() {
var showonlyone = function(thechosenone) {
$('.newboxes').each(function(index) {
if ($(this).attr("id") == thechosenone) {
$(this).show(200)}
else {
$(this).hide(600);
}
})
}
})
的功能必须正常工作,它只是该功能不能在列表中的项目,当点击调用。
http://jsfiddle.net/V4DTZ/ .....像这样 –
http://api.jquery.com/on/ – Quentin
http://stackoverflow.com/questions/1470488/var-keyword-and-use-it-or-omit-it – Quentin