Welcome to my website, have a nice day!
Dream it, Do it, Make it!

jquery常见selector选择器

1.根据name属性和类型选择

checkbox.jpg

$('input[type=radio][name=bedStatus]').change(function() {
    if (this.value == 'allot') {
        alert("Allot Thai Gayo Bhai");
    }else if (this.value == 'transfer') {
        alert("Transfer Thai Gayo");
    }
});

$('input:radio[name=typeTag]').change(function() {
        if (this.value == 'allot') {
            alert("Allot Thai Gayo Bhai");
        }
        else if (this.value == 'transfer') {
            alert("Transfer Thai Gayo");
        }
    });

$("input[type='radio'][name='radio']:checked").length == 0 ? "没有任何单选框被选中" : "已经有选中"; 

2.根据类型查找

var stdLength = $.find(".cycleCheckBoxAll").length;

3.查找父级label节点的兄弟div节点

function checkAllCircles(obj){
    if (obj.checked) {
        $(obj).parent('label').siblings('div').find('input[type="checkbox"]').each(function () {
            this.checked = true;
        });
    } else {
        $(obj).parent('label').siblings('div').find('input[type="checkbox"]').each(function () {
            this.checked = false;
        });
    }
}

4.查找找到的第一个元素

<ul>
  <li>list item 1</li>
  <li>list item 2</li>
  <li>list item 3</li>
  <li>list item 4</li>
  <li>list item 5</li>
</ul>

$('li').first().css('background-color', 'red');
赞(0)
未经允许禁止转载:Ddmit » jquery常见selector选择器

评论 抢沙发

登录

找回密码

注册