【发布时间】:2018-02-25 17:51:01
【问题描述】:
我正在为客户使用重复模块,以便在其页面上的每个产品元素上弹出一个弹出窗口。我的代码可以工作,但我想它非常臃肿,可能有一种方法可以更简洁地编写它。任何帮助找到一种更简洁的方式来编写它都会很有帮助。
$(document).ready(function() {
$("a.popbtn1").on("click", function(e) {
e.preventDefault();
$(this).simplePopup({ type: "html", htmlSelector: "#poppost1" });
});
$("a.popbtn2").on("click", function(e) {
e.preventDefault();
$(this).simplePopup({ type: "html", htmlSelector: "#poppost2" });
});
$("a.popbtn3").on("click", function(e) {
e.preventDefault();
$(this).simplePopup({ type: "html", htmlSelector: "#poppost3" });
});
$("a.popbtn4").on("click", function(e) {
e.preventDefault();
$(this).simplePopup({ type: "html", htmlSelector: "#poppost4" });
});
});
【问题讨论】:
标签: jquery dry code-cleanup