开发者

jquery generating ids and class

开发者 https://www.devze.com 2023-04-06 02:03 出处:网络
I would like to know how can I generate the following classes to game1, game2, game3, etc, automatically...

I would like to know how can I generate the following classes to game1, game2, game3, etc, automatically...

Generate a contentious classes

  • .game1-btn game1-btn, game2-btn, game3-btn,
  • .game1 - game2, game2, game3,
//Ml Game 1
$("#ml-games-collection .game1-btn").click(function () {
    $("#ml-display li.game").remove开发者_C百科Class("hide").css("display", "none");
    $("#ml-display .game1").show();
});

$("#ml-display .game1-ss1 img").bind("click", function () {
    $("#ml-display .game1-large-display").attr({
        "alt": "img alt 1 - screenshot 1",
        "src": "img1.jpg"
    });
});
$("#ml-display .game1-ss2 img").bind("click", function () {
    $("#ml-display .game1-large-display").attr({
        "alt": "img alt 2 - screenshot 1",
        "src": "img2.jpg"
    });
});
$("#ml-display .game1-ss3 img").bind("click", function () {
    $("#ml-display .game1-large-display").attr({
        "alt": "img alt 3 - screenshot 1",
        "src": "img3.jpg"
    });
});


I don't understand exactly what you mean but maybe you should take a look at the attribute starts with selector


simple : ( if i understood you correctly)

for (var i=0;i<5;i++)
{

$("#ml-games-collection .game"+i+"-btn").click(function () {
    $("#ml-display li.game").removeClass("hide").css("display", "none");
    $('#ml-display .game'+i).show();
});




}
0

精彩评论

暂无评论...
验证码 换一张
取 消