0

我使用 jQuery UI 对话框插件来显示一个确认框,用于span 像这样删除相应的。这是我的 JS 代码:

 $("#dialog-stergelu").dialog({ 
        autoOpen: false, 
        bgiframe: true, 
        resizable: false, 
        width: 400, 
        modal: true, 
        overlay: { 
            backgroundColor: '#000', 
            opacity: 0.5 
        }, 
        buttons: { 
            'Sterge': function() { 
                     window.location = $('.opener').attr('confirm');
             }, 
             'Anuleaza': function() { 
                      $(this).dialog('close'); 
              } 
         } 
  }); 
  $('.opener').click(function() { 
         $('#dialog-stergelu').dialog('open'); 
  }); 

这是HTML:

<div id="dialog-stergelu" title="Stergeti acest raport ? ">
   <p>
      <span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"> </span>Chiar doriti sa stergeti acesta lucrare ? (Apasati "Anuleaza" pentru anularea comenzi)
   </p>
</div>
<span class="opener" confirm="delete.php?id=213115">Delete</span>
<span class="opener" confirm="delete.php?id=22314">Delete</span>
<span class="opener" confirm="delete.php?id=222111">Delete</span>
<span class="opener" confirm="delete.php?id=215231">Delete</span>
<span class="opener" confirm="delete.php?id=223151">Delete</span>

我想confirm从 clicked中获取 attr span。现在它只得到第一个。

4

5 回答 5

1

您可以尝试将 url 存储在这样data$("#dialog-stergelu")元素中,然后打开它。像这样 :

$('.opener').click(function() { 
    var url= $(this).attr("confirm"); //really, why wont this work?
    $('#dialog-stergelu').data('url', url).dialog('open'); 
});

然后,在对话框的buttons选项中,

buttons: { 
    'Sterge': function() { 
        window.location = $(this).data("url");
    }, 
    'Anuleaza': function() { 
        $(this).dialog('close'); 
    } 
} 

这是一个工作演示:http: //jsbin.com/edudun/4/edit

于 2013-06-08T06:49:31.380 回答
0

尝试替换此行:

window.location = $(this).attr('confirm');

有了这个:

window.location = $('.opener').attr('confirm');
于 2013-06-08T06:33:47.517 回答
0

设置 window.location 后,浏览器更改 url,页面上的脚本将停止执行。

于 2013-06-08T06:34:02.093 回答
0

我认为你的问题是你想得到span被点击的是?而不是错误地选择第一个匹配的$('.opener')是?

您需要将点击回调修改为:

$('.opener').click(function(e) {  
    // jqEl is your specfic jQuery span.opener that was clicked.
    // You can pass it to the dialog using any number of methods.
    var jqEl = $(e.target); 

    ('#dialog-stergelu').dialog('open'); 
}); 
于 2013-06-08T06:39:37.687 回答
0
Try this code...

$("#dialog-stergelu").dialog({ 
    autoOpen: false, 
    bgiframe: true, 
    resizable: false, 
    width: 400, 
    modal: true, 
    overlay: { 
        backgroundColor: '#000', 
        opacity: 0.5 
    }, 
    buttons: { 
        'Sterge': function() { 
            window.location = $('#dialog-stergelu').data('confirm');
         }, 
         'Anuleaza': function() { 
             $(this).dialog('close'); 
         } 
    } 
}); 
$('.opener').click(function() { 
    $('#dialog-stergelu').data('confirm',$(this).attr('confirm'));
    $('#dialog-stergelu').dialog('open'); 
}); 
于 2013-06-08T06:47:07.847 回答