Javascript 根据选择的选项切换div
我想根据单击的锚定标记切换div,但无法切换。如果我使用id选择器,则会切换第一个div,但不会切换其余div,因为它们具有相同的id,即erong。有人能帮我解决这个问题吗…全部隐藏,只显示您想要的方法:Javascript 根据选择的选项切换div,javascript,jquery,html,ajax,jquery-ui,Javascript,Jquery,Html,Ajax,Jquery Ui,我想根据单击的锚定标记切换div,但无法切换。如果我使用id选择器,则会切换第一个div,但不会切换其余div,因为它们具有相同的id,即erong。有人能帮我解决这个问题吗…全部隐藏,只显示您想要的方法: function toggleDiv() { $("#myContent").toggle(); } 但是省去重新发明轮子和使用的麻烦。在javascript:toggleDiv($(this))这是指向窗口,而不是对象。看见因此,请更改以下代码: $('#
function toggleDiv() {
$("#myContent").toggle();
}
但是省去重新发明轮子和使用的麻烦。在
javascript:toggleDiv($(this))
这是指向窗口,而不是对象。看见因此,请更改以下代码:
$('#accordian>div').hide() // hide all divs within the accordian
.find('#selectedId').show(); // then show the one that matches the ID you want
此外,id应该是唯一的,并且在您的代码中您将有多个头锚元素。尝试在恢复html之前关闭脚本标记。是的,这很有效。非常感谢。我已经删除了id。我只是尝试了不同的奇数:)无论如何,非常感谢
$('#accordian>div').hide() // hide all divs within the accordian
.find('#selectedId').show(); // then show the one that matches the ID you want
"<a id='Headanchor' href='javascript:toggleDiv($(this));'>"
"<a id='Headanchor' href='#' onclick='return toggleDiv($(this));'>"
function toggleDiv(element) {
var x = element.next();
x.toggle();
return false;
}