我想切换3格。 在开始的情况下,我有第一个div,因为它的ID无法触发clic。 当我点击第二个或第三个div(触发)时,点击的DIV必须变得不可点击,其他点击可点击。jQuery toggle 3 Div
我附上我的活生生的例子:
HTML:
<div id = "not-selectable" class = "btn1">Div 1</div>
<div id = "selectable" class = "btn2">Div 2</div>
<div id = "selectable" class = "btn3">Div 3</div>
JAVASCRIPT:
$("#selectable").click(function(e) {
var className = $(this).attr('class');
alert(className);
if (className == "btn1") {
$("btn1").attr("selectable","not-selectable");
$("btn2").attr("not-selectable","selectable");
$("btn3").attr("not-selectable","selectable");
} else if (className == "btn2") {
$("btn2").attr("selectable","not-selectable");
$("btn1").attr("not-selectable","selectable");
$("btn3").attr("not-selectable","selectable");
} else if (className == "btn3") {
$("btn3").attr("selectable","not-selectable");
$("btn1").attr("not-selectable","selectable");
$("btn2").attr("not-selectable","selectable");
}
});
在这种情况下,当我点击第二个DIV,它应该成为unclickable ....但没有任何反应。
感谢您的帮助!
属性ID必须是u nique有两个相同的ID值是可选的 –
$(“div”).click(function(e)尝试这一个 –
你写了“不可点击”,但所有的选择器都说“不可选”。你的意思是,你的div应该是不可选或不可点击的?如果不能解释,那么你能解释为什么你需要它?点击元素时不应该发生什么。 – drakonli