1、html標(biāo)記
<ul id="attachText"> <li data-text="111"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >查看附件</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >刪除</a></li> <li data-text="222"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >查看附件</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >刪除</a></li> <li data-text="333"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >查看附件</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >刪除</a></li> </ul>
JS
1、獲取 li屬性 data-text的值用 ,隔開(kāi)
function GetValues() { var values = ""; var obj = $("#attachText li"); if(obj.length>0) { var len = $(obj).length-1; $.each(obj, function (index, value) { //表示為最后一個(gè)元素 if (index == len) { values += $(value).attr("data-text"); } else { values += $(value).attr("data-text") + ","; } }) } console.log(values); }
輸出結(jié)果;111,222,333
2、編輯的時(shí)候初始化ul的li項(xiàng)
function LoadAttach() { $("#attachText").html("");//先清空 var data="111,222,333"; var arr = data.split(','); $.each(arr, function (index, value) { $("#attachText").prepend("<li data-value=\"" + $.parseJSON(data).data + "\"><a>查看附件</a> <a>刪除</a></li>"); }); }
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com