我正在尝试使用jQuery来选中ul li
元素。
以下是ul li
元素:
<ul data-role="listview" data-inset="true" data-theme="d" data-dividertheme="c" id="layerslist"
class="ui-listview ui-listview-inset ui-corner-all ui-shadow ui-group-theme-d">
<li data-icon="check" class=""><a class="geomind-list-item ui-btn ui-btn-icon-right ui-icon-check"> "valves1" </a></li>
<li data-icon="check" class=""><a class="geomind-list-item ui-btn ui-btn-icon-right ui-icon-check"> "valves2" </a></li>
<li data-icon="check" class=""><a class="geomind-list-item ui-btn ui-btn-icon-right ui-icon-check"> "valves3" </a></li>
<li data-icon="check" class=""><a class="geomind-list-item ui-btn ui-btn-icon-right ui-icon-check"> "valves4" </a></li>
</ul>
我想制作一个具有li
文字的选中的"valves3"
元素。
如何检查具有li
文本的"valves3"
元素?
答案 0 :(得分:0)
不确定如何检查它,但是尝试类似的事情。
$('#layerslist li a').click(function() {
$("#layerslist li.checked").removeClass("checked");
$(this).parent().addClass("checked");
})
li.checked {
color: yellow;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul data-role="listview" data-inset="true" data-theme="d" data-dividertheme="c" id="layerslist" class="ui-listview ui-listview-inset ui-corner-all ui-shadow ui-group-theme-d">
<li data-icon="check" class=""><a class="geomind-list-item ui-btn ui-btn-icon-right ui-icon-check"> "valves1" </a></li>
<li data-icon="check" class=""><a class="geomind-list-item ui-btn ui-btn-icon-right ui-icon-check"> "valves2" </a></li>
<li data-icon="check" class=""><a class="geomind-list-item ui-btn ui-btn-icon-right ui-icon-check"> "valves3" </a></li>
<li data-icon="check" class=""><a class="geomind-list-item ui-btn ui-btn-icon-right ui-icon-check"> "valves4" </a></li>
</ul>