这是我的JavaScript代码:
<script type="text/javascript">
$(function () {
$('li').on('click', function (e) {
var menuItem = $(e.currentTarget);
if (menuItem.attr('aria-expanded') === 'true') {
$(this).attr('aria-expanded', 'false');
} else {
$(this).attr('aria-expanded', 'true');
}
});
});
如果我单击另一个li,我希望其他li设置为aria-expanded = false
答案 0 :(得分:0)
您可以使用jQuery的siblings()函数来获取其他type Period = "day" | "month" | "year";
let myPeriod: Period = "day";
const anyValue= {period: "wrong"};
myPeriod = anyValue.period; //error now
console.log(myPeriod);
元素:
li
答案 1 :(得分:0)
您可以先为所有<li>
元素将其设置为false,然后为您单击的元素启用它:
<script type="text/javascript">
$(function () {
$('li').on('click', function (e) {
var menuItem = $(e.currentTarget);
// set it to false for every element
menuItem.parent().children('li').attr('aria-expanded', 'false');
// set it to true for the element you clicked on
menuItem.attr('aria-expanded', 'true');
});
});
</script>