问题:
I'm using the jQuery quicksand plugin. 我正在使用jQuery quicksand插件。 I need to get the data-id of the clicked item and pass it to a webservice. 我需要获取所单击项的data-id并将其传递给webservice。 How do I get the data-id attribute? 如何获取data-id属性? I'm using the .on()
method to re-bind the click event for sorted items. 我正在使用.on()
方法重新绑定已排序项的click事件。
$("#list li").on('click', function() { // ret = DetailsView.GetProject($(this).attr("#data-id"), OnComplete, OnTimeOut, OnError); alert($(this).attr("#data-id")); });
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script> <ul id="list" class="grid"> <li data-id="id-40" class="win"> <a id="ctl00_cphBody_ListView1_ctrl0_SelectButton" class="project" href="#"> <img src="themes/clean/images/win.jpg" class="project-image" alt="get data-id" /> </a> </li> </ul>
解决方案:
参考一: https://stackoom.com/question/MHLy/如何获取data-id属性参考二: https://oldbug.net/q/MHLy/How-to-get-the-data-id-attribute
来源:oschina
链接:https://my.oschina.net/stackoom/blog/4254658