ul li遍历
var list = document.getElementsByTagName("li");
for (var i = 0; i < list.length; i++) {
$li = list[i];
}
$('#div').find('li').each(function() {
$(this).click(function() {
console.log($(this).index());
})
})
var terrainType;
$("#terrainAnalysis li").each(function(){
if($(this).hasClass('layui-this')){
terrainType = $(this).attr("data-type")
}
});
$("div").each(){
if($(this).css("display")=="block"){
alert('您想要的元素');
}
};
$("input[name='role'][value='"+roleId+"']").attr("checked", true);
jQuery操作select控件
var isChecked= $("#city").attr("checked");
var city= $("#city option:selected").val();
$('#city').empty();
existOptText = $("#city option").each(function() {
var op = $(this).text();
});
jQuery常用操作
$(".activeRate").html(data.activeRate);
- jQuery 动态添加、删除class,添加css样式
$(".activeRate").addClass("icon-upward");
$(".activeRate").removeClass("icon-upward");
$(".firstRate").css('color','#ff0914');
ul和li
$("ul").has("li").length > 0;
$("ul > li").length > 0;
$("ul").find("li").length > 0;
$('#id').siblings() 当前元素所有的兄弟节点
$('#id').prev() 当前元素前一个兄弟节点
$('#id').prevaAll() 当前元素之前所有的兄弟节点
$('#id').next() 当前元素之后第一个兄弟节点
$('#id').nextAll() 当前元素之后所有的兄弟节点