0

此处损坏代码的工作版本http://jsfiddle.net/Uey6W/8/

无法确定如何从点击功能更改另一个元素上的属性

狙击

$('#black').click(function() {
$('#blackbox').slideToggle('slow', function() {});
$('#yellowbox').slideUp();
});

单击此处,我​​希望不仅隐藏其他元素,还希望还原其他按钮

基本上,当另一个按钮切换到打开状态时,我如何将另一个按钮切换到关闭状态

$("#black").toggle(
    function () {
      var src = $(this).attr("src").replace("ready.png", "pressed.png");
      $(this).attr("src", src);
     },
    function () {
      var src = $(this).attr("src").replace("pressed.png", "ready.png");
      $(this).attr("src", src);
    }
);
$('#black').click(function() {
$('#blackbox').slideToggle('slow', function() {});
$('#yellowbox').slideUp();
});

$("#yellow").toggle(
    function () {
      var src = $(this).attr("src").replace("ready.png", "pressed.png");
      $(this).attr("src", src);
     },
    function () {
      var src = $(this).attr("src").replace("pressed.png", "ready.png");
      $(this).attr("src", src);
    }
);
$('#yellow').click(function() {
$('#yellowbox').slideToggle('slow', function() {});
$('#blackbox').slideUp();
});
4

3 回答 3

1

From what I can see in the api reference, toggle doesn't take two functions as parameters. And you're passing an empty function to slideToggle (just omit the empty function as a parameter if that's the intention). It looks like you're on the right train of thought with just a few errors.

Edit: Was looking at the wrong toggle. Correct documentation here.

于 2012-08-14T18:44:15.630 回答
0

您几乎可以通过以下方式实现完全相同的目标:

var btn1 = "ready.png",
    btn2 = "pressed.png";

$("#black, #yellow").on('click', function() {
    $("#black, #yellow").not(this).prop('src', this.src);
    this.src = this.src==btn1 ? btn2 : btn1;
    $('#'+this.id+'box').slideToggle('slow').siblings('div').slideUp('slow');
});

小提琴

于 2012-08-14T18:54:46.123 回答
0

答案一直在我面前为了恢复其他按钮我只是改变了点击语句

$('#black').click(function() {
$('#blackbox').slideToggle('slow', function() {});
$('#yellowbox').slideUp();
    $('yellow').atr('src', ready.png)
});
于 2012-08-14T18:50:29.107 回答