【问题标题】:passing the parameter to click function of jquery mobile simple dialog将参数传递给jQuery移动简单对话框的点击功能
【发布时间】:2012-06-27 08:22:56
【问题描述】:

我有以下jquery代码

function deleteAppointment(confirmationNumber)
{
//        alert(confirmationNumber);
     $('#left').simpledialog({
        'mode' : 'bool',
        'prompt' : 'Confirm Delete',
        'useModal': true,
        'buttons' : {
          'OK': {
            click:function () {
//                    alert(confirmationNumber);
                var link;       
                link = ROOT_URL+'Queue/cancelreservation/confirmnumber/'+confirmationNumber;        
                $.ajax({
                    url: link,
                    type: 'GET',
                    async: true,
                    success: function(data){
                        renderAgain();
                        addRightPane();
                        $(APPOINTMENT_LIST_CLASS).animate({
                            scrollTop: 0
                        });

                    },
                    error: function(){
                        /*@TODO : What if the ajax request fails */
                    }
                });
            }

          },
          'Cancel': {
            click: function () {
              $('#dialogoutput').text('Cancel');
            },
            icon: "delete",
            theme: "c"
          }
        }

    });             
}

问题是我传给删除约会功能的确认号只是第一次传,下次不更新。它保存旧确认号的值,所以我发现我必须将确认号传递给 click 函数。任何人都可以帮助我如何做到这一点?或者我在这里缺少什么?

【问题讨论】:

  • 构象号是存储在某个html参数还是元素的某个id中?
  • 从另一个函数传到这里

标签: jquery jquery-plugins jquery-mobile modal-dialog


【解决方案1】:

在 jquerymobile 获得更多经验后,我找到了更优雅、更正确的方法来解决此问题

只使用简单对话框的属性

'cleanOnClose' : true

这将解决您的问题

【讨论】:

    【解决方案2】:

    我相信你的删除按钮是这样的

    <a class="deleteappoinment" href="javascript:void(0);" id="12">Delete</a> //here 12 is an example of conformation id, change it accordingly
    
    $(document).ready(function(){
        $('.deleteappoinment').click(function(){
    
                deleteAppointment($(this).attr('id'));
    
          });
        });
    
    function deleteAppointment(confirmationNumber){
     //code
    }
    

    【讨论】:

    • 好吧,就像这样..但问题出在代码部分。每次我们调用 deleteappointment 函数时,确认号都不会更新。
    • 对话框上方的警报给出了我需要的值。而ok按钮的点击功能内的警报保留其旧值
    【解决方案3】:

    想要做和你一样的事情,一个可以重新填充一个简单对话框的函数,但问题是 onclick 必须解除绑定并再次绑定,但我不知道怎么做。我只是做了一个解决方法并使用传递参数的全局变量

    这应该可以解决问题...如果有人知道如何重新绑定事件,请告诉我们

    var selected;
    
     function deleteAppointment(confirmationNumber)
    {
    selected = confirmationNumber;
    //        alert(confirmationNumber);
         $('#left').simpledialog({
            'mode' : 'bool',
            'prompt' : 'Confirm Delete',
            'useModal': true,
            'buttons' : {
              'OK': {
                click:function () {
    //                    alert(selected );
                    var link;       
                    link = ROOT_URL+'Queue/cancelreservation/confirmnumber/'+selected ;        
                    $.ajax({
                        url: link,
                        type: 'GET',
                        async: true,
                        success: function(data){
                            renderAgain();
                            addRightPane();
                            $(APPOINTMENT_LIST_CLASS).animate({
                                scrollTop: 0
                            });
    
                        },
                        error: function(){
                            /*@TODO : What if the ajax request fails */
                        }
                    });
                }
    
              },
              'Cancel': {
                click: function () {
                  $('#dialogoutput').text('Cancel');
                },
                icon: "delete",
                theme: "c"
              }
            }
    
        });             
    }
    

    【讨论】:

    • 实际上我也采用了这个解决方案,即使用全局变量。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    • 2012-05-06
    • 1970-01-01
    • 2010-09-28
    相关资源
    最近更新 更多