如何获取data-id属性?

↘锁芯ラ 提交于 2020-04-27 06:00:29

问题:

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!