jQuery လိုက်လျော့ - filter() စမ်းသပ်

အကျိုးသတ္တု

အားလုံးသော div အရောင်ပြောင်းပြီး "middle" အမည်ရှိ အကြွေးအကြေး ပေါင်းထည်တင်ပါ

("div").css("background", "#c8ebcc")
  .filter(".middle")
  .filter(".middle")

ကျွန်ုပ်တို့ ကြိုးစား ကြည့်ပါ

.css("border-color", "red");

definition and usage

filter() method သည် အမှုကြောင်း အကြွင်းအကျန် အမှုကြောင်း အပေါ် အမှုကြောင်း ကို ကိုင်ပေးသည်。

syntaxdescription.filter(
) parameter
description selector

string value တစ်ခု ဖြစ်၍ အရင်းအမြစ် အချက်အလက် ကို သတ်မှတ်သည်။

အကြောင်းကြောင်း အသိပေး

အောက်ပါ ပုံစံအတိုင်း ပုံစံ အနှစ်တရာ ကို ကြည့်ပါ:

<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>
  <li>list item 6</li>
</ul>

ထို့ကြောင့် သင်တို့သည် အစားအထား စာအုပ် အချက်အလက် အပေါ် အစားအထား စာအုပ် အချက်အလက် ကို ရွေးချယ်နိုင်ပါသည်:

$('li').filter(':even').css('background-color', 'red');

ကျွန်ုပ်တို့ ကြိုးစား ကြည့်ပါ

ထိုအချက်အလက် သည် အောက်ပါ အချက်အလက် ကို အသုံးပြုသည်။ အောက်ပါ အချက်အလက် သည် အသုံးပြုသည်။

filter function ကို အသုံးပြုပါ

ထို့နောက်သာ ဘက်တွင် အမှုကြောင်း ကို အကူအညီ ပြုလုပ်သော ဘက်တွင် အမှုကြောင်း ကို ရွေးချယ်သည်။ ရှိသော အမှုကြောင်း အတွက် အကြောင်းအရာ သည် လုပ်ကိုင်သည်။ အကြောင်းအရာ သည် လုပ်ကိုင်သေးသည်။

အောက်ပါ ပုံစံအတိုင်း ပုံစံ အနှစ်တရာ ကို ကြည့်ပါ:

<ul>
  <li><strong>list</strong> item 1 - one strong tag</li>
  <li><strong>list</strong> item <strong>2</strong>
   - two <span>strong tags</span></li>
  <li>list item 3</li>
  <li>list item 4</li>
  <li>list item 5</li>
  <li>list item 6</li>
</ul>

ထို့ကြောင့် သင်တို့သည် အစားအထား စာအုပ် အချက်အလက် အပေါ် အစားအထား စာအုပ် အချက်အလက် ကို ရွေးချယ်နိုင်ပါသည်:

$('li').filter(function(index) {
  return $('strong', this).length == 1;
}).css('background-color', 'red');