我想压缩一下这段代码:
$("a.clearfix.scalability").click(function() {
$("h2.cases-header").fadeOut(100, function () {
$("h2.cases-header").text("Scalability").fadeIn(100);
})
})
$("a.clearfix.international-compliance").click(function() {
$("h2.cases-header").fadeOut(100, function () {
$('h2.cases-header').text("International Compliance").fadeIn(100);
})
})
$("a.clearfix.rewards").click(function() {
$("h2.cases-header").fadeOut(100, function () {
$('h2.cases-header').text("Rewards Program").fadeIn(100);
})
})
$("a.clearfix.mom-baby").click(function() {
$("h2.cases-header").fadeOut(100, function () {
$('h2.cases-header').text("Mom & Baby").fadeIn(100);
})
})
$("a.clearfix.online-travel-agency").click(function() {
$("h2.cases-header").fadeOut(100, function () {
$('h2.cases-header').text("Online Travel Agency").fadeIn(100);
})
})
$("a.clearfix.food-delivery").click(function() {
$("h2.cases-header").fadeOut(100, function () {
$('h2.cases-header').text("Food Delivery").fadeIn(100);
})
})我想知道设置它的正确方式。我从两个独立的数组开始,它们包含了我需要插入到jquery函数中的信息,但是我不确定如何让它循环,或者我是否正确地调用了数组对象。到目前为止我的代码是:
var anchors = ["a.clearfix.scalability", "a.clearfix.international-
compliance", "International Compliance", "a.clearfix.mom-baby",
"a.clearfix.food-delivery"];
var copy = ["Scalability", "International Compliance", "Rewards Program",
"Online Travel Agency", "Food Delivery"];
$(anchors[0]).click(function() {
$("h2.cases-header").fadeOut(100, function () {
$("h2.cases-header").text(copy[0]).fadeIn(100);
})
})https://stackoverflow.com/questions/44685362
复制相似问题