我觉得我在做脏代码,虽然它工作得很好......
在这种情况下,如何用常规 JQuery 选择器替换那些 IF 语句:
见代码+提琴手
<html>
<body>
<a href="#b" class="cssPauseAll" historyID="12">Pause All</a><br/>
<a href="#b" itemHistoryID="12" ContentID="45">AA</a><br/>
<a href="#b" itemHistoryID="12" ContentID="14">BB</a><br/>
<a href="#b" itemHistoryID="12" ContentID="78">AA</a><br/>
<a href="#b" class="cssPauseAll" historyID="13">Pause All</a><br/>
<a href="#b" itemHistoryID="13" ContentID="45">BB</a><br/>
<a href="#b" itemHistoryID="13" ContentID="14">BB</a><br/>
<a href="#b" itemHistoryID="13" ContentID="78">CC</a><br/>
</body>
</html>
$(document).ready(function () {
$(document).on("click","a.cssPauseAll[historyID]", function () {
var historyID = $(this).attr("historyID");
//alert("historyID from PauseAll " + $(this).attr("historyID"));
$(document).find("[itemHistoryID]").each(function() {
var itemHistoryID = $(this).attr("itemHistoryID");
if(historyID == itemHistoryID)
{
alert($(this).attr("ContentID"));
}
});
});
});