weixin_33726943 2014-08-04 17:50 采纳率: 0%
浏览 25

重用按钮jQuery

I have 2 buttons which each one appears after an AJAX call. This is the code which work in these buttons:

 $('#detalles').on('click', 'button', function() {
    var id = $(this).data('estatus');
    var val = $(this).val();
    estatusObj[id](val);
});

And estatusObj have the next:

etc...
'4': function(val) {
        if (val === 'no') {
            if (confirm('¿Desea eliminar la oportunidad ' + nombre + '?')) {
                $.post('oportunidad_query.php', {'id': oportunidad, 'accion': 'delete'})
                        .done(function() {
                            $('#detalles').on('dialogclose', function(event, ui) {
                                location.reload();
                            });
                            $('#detalles').dialog({buttons: {'Cerrar': function() {
                                        $(this).dialog("close");
                                    }}
                            }).html('<h3>¡' + nombre + ' eliminado!</h3>');
                        });
            }
        }
        else {
            alert('hola');
            $('#detalles section:first-of-type p+p').html('¿Ajustar cotización?');
            $('#detalles').off('click', 'button', function() {
                alert('Lo hizo');
            });
        }
    },

The buttons says 'Yes' and 'No'. If 'No', delete data into the database (this works). But when click 'Yes', I want to keep those buttons, but with differents click events. How can do it?

  • 写回答

1条回答 默认 最新

  • weixin_33713707 2014-08-04 18:08
    关注
    function(val) {
        if($('#detalles button').attr('rel')=='second'){
            if (val === 'no') {
                alert("Second No");
            }else{
                alert("Second yes");
            }
        }else{
            if (val === 'no') {
                if (confirm('¿Desea eliminar la oportunidad ' + nombre + '?')) {
                    $.post('oportunidad_query.php', {
                        'id': oportunidad, 
                        'accion': 'delete'
                    })
                    .done(function() {
                        $('#detalles').on('dialogclose', function(event, ui) {
                            location.reload();
                        });
                        $('#detalles').dialog({
                            buttons: {
                                'Cerrar': function() {
                                    $(this).dialog("close");
                                }
                            }
                        }).html('<h3>¡' + nombre + ' eliminado!</h3>');
                    });
                }
            }
            else {
                alert('hola');
                //$('#detalles section:first-of-type p+p').html('¿Ajustar cotización?');
                $('#detalles button').attr('rel','second');
            }
        }
    
    }
    

    You can add some attribute rel into buttons element.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿