這兩天在做某個功能
需要把列表頁面中的各個CHECKBOX帶出
參考同事的CODE
但卻一直搞不清楚是怎麼回事]


 $("input[id^='XXX']")

爬文總算爬到是"以id屬性以XXX開始的所有input標籤 "

 

<html>

 <div class="custom-control custom-checkbox d-inline-block">
      <input type="checkbox" class="custom-control-input" value="@(Model.ElementAt(i).IsAdd)" id="Add_@(Model.ElementAt(i).ID)" checked="checked">
      <label class="custom-control-label" for="Add_@(Model.ElementAt(i).ID)"></label>
</div>

</html>

 

<script>

var SelectedAdd = [];
$("input[id^='Add_']").each(function () {
   if ($(this).prop("checked")) {
       SelectedAdd .push({
       ID: $(this).attr('id').replace("Add_", "")                   
    });
}

</script>

 

以下來自下方參考文章

$("input[id^='code']");//id屬性以code開始的所有input標籤

$("input[id$='code']");//id屬性以code結束的所有input標籤

$("input[id*='code']");//id屬性包含code的所有input標籤

$("input[name^='code']");//name屬性以code開始的所有input標籤

$("input[name$='code']");//name屬性以code結束的所有input標籤

$("input[name*='code']");//name屬性包含code的所有input標籤

 

 

文章參考   JQUERY_選擇器中的萬用字元  

https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/271569/

文章標籤
全站熱搜
創作者介紹
創作者 andrea77222 的頭像
andrea77222

Andrea's Hello world

andrea77222 發表在 痞客邦 留言(0) 人氣(2)