Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript modal中的jquery函数只在第一次打开时工作,在关闭和重新打开后停止工作_Javascript_Jquery_Modal Dialog - Fatal编程技术网

Javascript modal中的jquery函数只在第一次打开时工作,在关闭和重新打开后停止工作

Javascript modal中的jquery函数只在第一次打开时工作,在关闭和重新打开后停止工作,javascript,jquery,modal-dialog,Javascript,Jquery,Modal Dialog,我使用jquery模式,在每个模式中我都有一个表单。然后我将某些jquery函数加载到表单元素中,例如jquery autocomplete 当我第一次打开模式时,脚本中的所有jquery函数都可以正常工作,但一旦我关闭第一个模式并再次打开,所有函数都无法工作 就好像它们在页面加载时被绑定到表单上一样,然后当点击模式按钮时,它会工作,然后关闭模式会解除绑定 有人知道为什么在第一次模式打开/关闭后停止工作吗 $(document).ready(dialogForms); function dial

我使用jquery模式,在每个模式中我都有一个表单。然后我将某些jquery函数加载到表单元素中,例如jquery autocomplete

当我第一次打开模式时,脚本中的所有jquery函数都可以正常工作,但一旦我关闭第一个模式并再次打开,所有函数都无法工作

就好像它们在页面加载时被绑定到表单上一样,然后当点击模式按钮时,它会工作,然后关闭模式会解除绑定

有人知道为什么在第一次模式打开/关闭后停止工作吗

$(document).ready(dialogForms);
function dialogForms() {    
 $('a.menubutton').click(function() {
    var a = $(this);
    $.get(a.attr('href'),function(resp){
      var dialog = $('<div>').attr('id','formDialog').html($(resp).find('form:first').parent('div').html());
      $('body').append(dialog);
      dialog.find(':submit').hide();
      dialog.dialog({
        title: a.attr('title') ? a.attr('title') : '',
        modal: true,
        buttons: {
          'Save': function() {

                if($(this).find('form').valid()){
                // do stuff if form validates
                submitFormWithAjax($(this).find('form'));               
                $('#homepage').trigger('click');    
                $(this).dialog('close');
                } 
                else {

                }             
                },
          'Cancel': function() {$(this).dialog('close');}
        },
        width: 650,
        height: 400,        
        show: "fade",
        hide: "fade"
      });

$('#edit_vle').bind('change', function (e) { 
    if( $('#edit_vle').val() == 'FE') {
      $('#fe_automcomplete1').show();
      $('#he_automcomplete1').hide();
      $("#edit_he_title").val("");
      $("#edit_he_code").val("");
    }
    else{
      $('#fe_automcomplete1').hide();
      $('#he_automcomplete1').show();
      $("#edit_fe_title").val("");
      $("#edit_fe_code").val("");
    }         
});


$('#delete_vle').bind('change', function (e) { 
    if( $('#delete_vle').val() == 'FE') {
      $('#fe_automcomplete2').show();
      $('#he_automcomplete2').hide();
      $("#delete_he_title").val("");
      $("#delete_he_code").val("");
    }
    else{
      $('#fe_automcomplete2').hide();
      $('#he_automcomplete2').show();
      $("#delete_fe_title").val("");
      $("#delete_fe_code").val("");
    }         
});


    var epronames = [<?php 
    $eprotmp = Array();
    while($eprorow = mssql_fetch_array($epro_course)) $eprotmp[] = 
    '{
                title: "'.$eprorow['Name'].'",
                label: "'.$eprorow['Code'].' - '.$eprorow['Name'].'",
                code: "'.$eprorow['Code'].'",
                user: "'.$eprorow['fname'].' '.$eprorow['sname'].'",
    }'; 
    echo join(',', $eprotmp);
?>];

    var fenames = [<?php 
    $fetmp = Array();
    while($ferow = mysql_fetch_array($feinactive)) $fetmp[] = 
    '{
                title: "'.$ferow['course'].'",
                label: "'.$ferow['shortname'].' - '.$ferow['course'].'",
                code: "'.$ferow['shortname'].'",
    }'; 
    echo join(',', $fetmp);
?>];

    var henames = [<?php 
    $hetmp = Array();
    while($herow = mysql_fetch_array($heinactive)) $hetmp[] = 
    '{
                title: "'.$herow['course'].'",
                label: "'.$herow['shortname'].' - '.$herow['course'].'",
                code: "'.$herow['shortname'].'",
    }'; 
    echo join(',', $hetmp);
?>];

        $("#title").autocomplete({
            minLength: 3,
            source: epronames,
            focus: function( event, ui ) {
                $("#title").val( ui.item.label );
                return false;
            },
            select: function( event, ui ) {
                $("#title").val( ui.item.title );
                $("#code").val( ui.item.code );
                $("#ctl").val( ui.item.user );
                return false;
            },
            change: function(event, ui) {
            if (!ui.item) {
                $("#title").val("");
            }
            }
        })
        .data( "autocomplete" )._renderItem = function( ul, item ) {
            return $( "<li></li>" )
                .data( "item.autocomplete", item )
                .append( "<a>" + item.label + "</a>" )
                .appendTo( ul );
        };



        $("#edit_he_title").autocomplete({
            minLength: 3,
            source: henames,
            focus: function( event, ui ) {
                $("#edit_he_title").val( ui.item.label );
                return false;
            },
            select: function( event, ui ) {
                $("#edit_he_title").val( ui.item.title );
                $("#edit_he_code").val( ui.item.code );
                return false;
            },
            change: function(event, ui) {
            if (!ui.item) {
                $("#edit_he_title").val("");
            }
            }
        })
        .data( "autocomplete" )._renderItem = function( ul, item ) {
            return $( "<li></li>" )
                .data( "item.autocomplete", item )
                .append( "<a>" + item.label + "</a>" )
                .appendTo( ul );
        };



        $("#edit_fe_title").autocomplete({
            minLength: 3,
            source: fenames,
            focus: function( event, ui ) {
                $("#edit_fe_title").val( ui.item.label );
                return false;
            },
            select: function( event, ui ) {
                $("#edit_fe_title").val( ui.item.title );
                $("#edit_fe_code").val( ui.item.code );
                return false;
            },
            change: function(event, ui) {
            if (!ui.item) {
                $("#edit_fe_title").val("");
            }
            }
        })
        .data( "autocomplete" )._renderItem = function( ul, item ) {
            return $( "<li></li>" )
                .data( "item.autocomplete", item )
                .append( "<a>" + item.label + "</a>" )
                .appendTo( ul );
        };      






if($("#clearform").length > 0){
$("#clearform").click(function() {
    $("#title").val('');
    $("#code").val('');
    $("#ctl").val('');
});
}

if($("#delete_fe_clearform").length > 0){
$("#delete_fe_clearform").click(function() {
    $("#delete_fe_title").val('');
    $("#delete_fe_code").val('');
});
}
if($("#edit_fe_clearform").length > 0){
$("#edit_fe_clearform").click(function() {
    $("#edit_fe_title").val('');
    $("#edit_fe_code").val('');
});
}

if($("#delete_he_clearform").length > 0){
$("#delete_he_clearform").click(function() {
    $("#delete_he_title").val('');
    $("#delete_he_code").val('');
});
}
if($("#edit_he_clearform").length > 0){
$("#edit_he_clearform").click(function() {
    $("#edit_he_title").val('');
    $("#edit_he_code").val('');
});
}


}, 'html');
return false;
});

}

function submitFormWithAjax(form) {
  form = $(form);
  $.ajax({
    url: form.attr('action'),
    data: form.serialize(),
    type: (form.attr('method')),
    dataType: 'script',
    success: function(data){
   }
  });
  return false;
}
$(文档).ready(dialogForms);
函数dialogForms(){
$('a.menubutton')。单击(函数(){
var a=$(本);
$.get(a.attr('href'),函数(resp){
var dialog=$('').attr('id','formDialog').html($(resp).find('form:first').parent('div').html());
$('body')。追加(对话框);
dialog.find(':submit').hide();
对话({
标题:a.attr('title')?a.attr('title'):“”,
莫代尔:是的,
按钮:{
“保存”:函数(){
if($(this.find('form').valid()){
//如果表单验证,则执行这些操作
submitFormWithAjax($(this.find('form'));
$(“#主页”).trigger('click');
$(this.dialog('close');
} 
否则{
}             
},
“取消”:函数(){$(this).dialog('close');}
},
宽度:650,
身高:400,
显示:“褪色”,
隐藏:“褪色”
});
$('#edit_vle')。绑定('change',函数(e){
if($('#edit_vle').val(){
$('fe#u automccomplete1').show();
$('he#u automcomcomplete1').hide();
$(“编辑标题”).val(“”);
$(“#编辑代码”).val(“”);
}
否则{
$('fe#u automccomplete1').hide();
$('he#u automcomcomplete1').show();
$(“#编辑#fe#U标题”).val(“”);
$(“#编辑#fe#U代码”).val(“”);
}         
});
$('#delete_vle')。绑定('change',函数(e){
if($('#delete_vle').val()=='FE'){
$('fe#u automcomplete 2').show();
$('he#u automcomcomplete2').hide();
$(“#删除#标题”).val(“”);
$(“#删除#代码”).val(“”);
}
否则{
$('fe#u automccomplete2').hide();
$('he#u automcomcomplete2').show();
$(“#删除#fe#u title”).val(“”);
$(“#删除#fe#U代码”).val(“”);
}         
});
var-epronames=[];
var fenames=[];
var henames=[];
$(“#标题”).autocomplete({
最小长度:3,
资料来源:epronames,
焦点:功能(事件、用户界面){
$(“#title”).val(ui.item.label);
返回false;
},
选择:功能(事件、用户界面){
$(“#title”).val(ui.item.title);
$(“#代码”).val(ui.item.code);
$(“#ctl”).val(ui.item.user);
返回false;
},
更改:功能(事件、用户界面){
如果(!ui.item){
$(“#标题”).val(“”);
}
}
})
.数据(“自动完成”)。\u renderItem=功能(ul,项目){
返回$(“
  • ”) .data(“item.autocomplete”,item) .append(“
    我将jquery函数放入open方法中

    open: function(){
    
    要关闭对话框而不是使用,请执行以下操作:

    $(this).dialog('close');
    
    我曾经

    dialog.remove();
    

    现在,每次打开对话框时,我的函数都能正常工作

    您能为我提供小提琴吗
    dialog.remove();