关于jqueryui对话框内元素的Javascript

时间:2016-03-01 21:24:45

标签: jquery jquery-ui jquery-ui-dialog

我不知道如何让jquery使用我的jquery-ui模式中的元素。我知道你可以把js放在对话框的.load()中,当我这样做时可以得到警告,但是我想要一个.click - 这样我的jqueryui对话框中的按钮就会分配给它们.click事件。我无法想象这一个。这是我的代码

编辑 - 好吧,在/ *可能做其他的事情* /在我点击的代码中' add-btn',而不是' .add-btn&# 39; - 如果您将事件放入对话框加载

,则此方法有效
var edit_let_url;
 $( "#edit-let-modal" ).dialog({
autoOpen: false,
width: 'auto',
maxWidth:600,
height: 450,//$(window).height()-90,//'auto',
//maxHeigth:300,
        position: { my: "center top", at: "center top" },
modal: true,
fluid: true,
        resizable:false,


     open: function () {
        // call LOAD after open
        $("#edit-let-modal").load(edit_let_url, function() {
        // call fluid dialog AFTER load


         fluidDialog();

/*  MAYBE DO OTHER SHIT */

alert('yo - the dialog loaded');
$( this ).on( "click", "add-btn", function() {
alert('this click event not happening');

});//end dialog


        });
    },

buttons: {
"Save": function() {
    $.post(edit_let_url,
    $('#edit-let-form').serializeArray(),
    function(data){
        if (data){

        //pass ex_id as data for preview redirect

window.location.href = "/app/letters_config/";

        }else{alert('Did not save');
        $('#edit-let-form').html(data);}
    })
$( this ).dialog( "close" );
},//end save
Cancel: function() {
$( this ).dialog( "close" );
}//end cancel
}//end buttons


});




$('#LettTable').on('click touchstart','.edit_lett', function (){
//$('.edit_lett').click( function (){
edit_let_url=$(this).attr('name');
       // alert (edit_let_url);
//$( "#edit-let-modal" ).load(edit_let_url).dialog( "open" );
          $( "#edit-let-modal" ).dialog( "open" );//.load(urlvar).dialog( "open" );
});

模态窗口的html

<h2>Edit letter text</h2>

<form method='POST' id="edit-let-form">
{% csrf_token %}
{{ form.as_p }}

</form>



<button class="add-btn jackedbtn" id='[ass]' role="button">Assesment</button>
<button class="add-btn jackedbtn" id='[pers_hx_sur]' role="button">Save CSV (saves to file for later access)</button>

0 个答案:

没有答案