The following editor will bring you some operation notes for jquery operation ul (dry information). The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look
1. html tag
##
<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. Get the value of li attribute data-text, separated by
function GetValues() { var values = ""; var obj = $("#attachText li"); if(obj.length>0) { var len = $(obj).length-1; $.each(obj, function (index, value) { //表示为最后一个元素 if (index == len) { values += $(value).attr("data-text"); } else { values += $(value).attr("data-text") + ","; } }) } console.log(values); }
##2. Initialize the li item of ul when editing
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>"); }); }
The above is the detailed content of Summary of jquery operation ul skills. For more information, please follow other related articles on the PHP Chinese website!