Javascript。以下工作的,除了我想要增加2个特色的按钮的状态。

  1. 当一个用户点击按钮之一,其他按钮,不是点击获得一个新的类别(看起来).

  2. 两个按钮的国家应该改变不可点击.

[div id="1" class="__button_image"] [/div]
[div id="2" class="__button_image"] [/div]
$("div.__button_image").mouseover(function () {
    $(this).addClass("__button_image_hover");
});

$("div.__button_image").mouseout(function () {
    jq(this).removeClass("__button_image_hover");
});

$("div.__button_image").click(function () { 
    $(this).removeClass("__button_image_hover");
    $(this).addClass("__button_image_clicked");

    jQuery.get('/do/request');        
});
有帮助吗?

解决方案

这里是最后的码我去:

$("div.__button_image").mouseover(function () {
    $(this).addClass("__button_image_hover");
});

$("div.__button_image").mouseout(function () {
    $(this).removeClass("__button_image_hover");
});

$("div.__button_image").click(function () {

    /** change button look to 'clicked' */
    $(this).addClass("__button_image_clicked");

    /** get the id of the current button */
    b_id = $(this).attr('id');

    /** unbind both vote buttons for *no* interaction */
    $("div.__button_image").unbind('click');
    $("div.__button_image").unbind('mouseover');
    $("div.__button_image").unbind('mouseout');

    /**
     * wire the .each function to iterate the classes 
     * so we can change the look of the one that was 
     * not clicked.
    */
    $('div.__button_image').each(function() {
      button_id = $(this).attr('id');
      if(button_id!=b_id) {
         $('#'+button_id).removeClass("__button_image");
         $('#'+button_id).addClass("__button_image_gray");  

    }
});

jQuery.get('/do/request?id='+b_id); 
$(this).parent().css('cursor', 'default');

其他提示

有什么问题吗?我唯一可以看到你的失踪是

$("div.__button_image").unbind('click');

这将删除的"点击"处理程序(其设置回来的默认)。

我会改变你的点击()处理程序:

$("div.__button_image").click(function () { 
    $(this).removeClass("__button_image_hover");
    $(this).addClass("__button_image_clicked");

    /*
     * Add look class to all buttons, then remove it from this one
     */
    $("div.__button_image").addClass("look");
    $(this).removeClass("look");

    /*
     * Remove click handler from all buttons
     */
    $("div.__button_image").unbind('click');

    jQuery.get('/do/request');        
});

这个总是为我工作(也改变的透明度为80%和变化的标等)

$("#buttonDivId").css({opacity: 0.8, cursor: "wait"}).prop("disabled", true);

如果您使用的便捷可以使用禁用的方法。

$("selector").button("disable");

http://api.jqueryui.com/button/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top