<ul class="submenu">
<li class="lstnetdays"><a href="NetDaysInAR.html">Net Days In AR</a></li>
嗨,我有ul和li标签,我的要求是当我点击li标签时我想将ul类名改为“submenunew”。
答案 0 :(得分:1)
这对我有用
HTML
<ul class="submenu">
<li>Net Days In AR 1</li>
<li>Net Days In AR 2</li>
<li>Net Days In AR 3</li>
</ul>
的JavaScript
var elements = document.getElementsByTagName('li');
for (var i = 0, len = elements.length; i < len; i++) {
elements[i].onclick = function () {
this.parentNode.className = "submenunew";
}
}
的jQuery
$('li').on('click', function(){
$(this).parent().attr('class', 'submenunew');
});
答案 1 :(得分:1)
使用类名选择li并添加事件处理程序
QStandardItemModel