jquery根據介面返回的值來設定asp:CheckBoxList的選中值

來源:互聯網
上載者:User

標籤:style   blog   color   io   資料   for   cti   div   

介面返回一個json的值,然後通過jquery來選中asp:CheckBoxList相應選中的值

<asp:CheckBoxList runat="server" RepeatColumns="4"                                            ID="cklistLMLX">                                            <asp:ListItem Text="柏油" Value="柏油"></asp:ListItem>                                            <asp:ListItem Text="水泥" Value="水泥"></asp:ListItem>                                            <asp:ListItem Text="彩道" Value="彩道"></asp:ListItem>                                            <asp:ListItem Text="綠化" Value="綠化"></asp:ListItem>                                            <asp:ListItem Text="快車道" Value="快車道"></asp:ListItem>                                            <asp:ListItem Text="慢車道" Value="慢車道"></asp:ListItem>                                            <asp:ListItem Text="行人路" Value="行人路"></asp:ListItem>                                            <asp:ListItem Text="小區道" Value="小區道"></asp:ListItem>                                        </asp:CheckBoxList>

瀏覽器查看到的代碼如下:

<table id="cklistLMLX" border="0"><tbody><tr><td><input id="cklistLMLX_0" type="checkbox" name="cklistLMLX$0" checked="checked"><label for="cklistLMLX_0">柏油</label></td><td><input id="cklistLMLX_2" type="checkbox" name="cklistLMLX$2"><label for="cklistLMLX_2">彩道</label></td><td><input id="cklistLMLX_4" type="checkbox" name="cklistLMLX$4"><label for="cklistLMLX_4">快車道</label></td><td></tr><tr></tbody></table>

返回介面 lmlx資料如下: 小區道,行人路

    function SetCheckboxList(lmlx) {        $("#cklistLMLX").find("input[type=checkbox]").each(function (i) {
//alert($(this).val()); 這種方法是錯誤的 // alert($(this).next().text()); if (lmlx.indexOf($(this).next().text()) >= 0) { $(this).attr("checked", ‘true‘); } else { $(this).removeAttr("checked"); } }); }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.