【问题标题】:How do i convert 5 click functions into one with changes values如何将 5 个单击功能转换为一个具有更改值的功能
【发布时间】:2009-06-09 11:51:50
【问题描述】:

如何将 5 个点击功能合二为一?例如

$("div#styleswitcher a.green").click(function () {
    $("container").css({ 'background': 'green' });
});

$("div#styleswitcher a.blue").click(function () {
    $("container").css({ 'background': 'blue' });
});

$("div#styleswitcher a.red").click(function () {
    $("container").css({ 'background': 'red' });
});

$("div#styleswitcher a.yellow").click(function () {
    $("container").css({ 'background': 'yellow' });
});

【问题讨论】:

    标签: javascript jquery css


    【解决方案1】:

    想到这个:

    $("#styleswitcher a").click(function ()
    {
        $("container").css("background-color", this.className);
    });
    

    假设背景颜色应该是类名,如您的示例所示

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      • 2018-05-22
      • 1970-01-01
      • 2021-02-02
      • 2023-03-20
      • 2019-12-13
      • 1970-01-01
      相关资源
      最近更新 更多