Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.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 jQuery对话框和ajax回发_Javascript_Jquery_Postback - Fatal编程技术网

Javascript jQuery对话框和ajax回发

Javascript jQuery对话框和ajax回发,javascript,jquery,postback,Javascript,Jquery,Postback,我网站上的一个页面每15秒自动重新加载一次。这是通过使用jQuery的.ajax函数完成的 我的问题是,每次用户加载页面时,对话框中的表单都可以正常工作。 但是当页面本身自动重新加载时,输入会被移到表单之外 互联网上的许多人写道,通过在找到的第一个表单中添加div,可以将其移回表单中。我的问题是,当我尝试将“输入包装器”移回表单时,我遇到了一个hirachy问题 有人能帮忙吗?或者指出另一种解决方案 我的jQuery脚本: <script type='text/javascript'>

我网站上的一个页面每15秒自动重新加载一次。这是通过使用jQuery的.ajax函数完成的

我的问题是,每次用户加载页面时,对话框中的表单都可以正常工作。 但是当页面本身自动重新加载时,输入会被移到表单之外

互联网上的许多人写道,通过在找到的第一个表单中添加div,可以将其移回表单中。我的问题是,当我尝试将“输入包装器”移回表单时,我遇到了一个hirachy问题

有人能帮忙吗?或者指出另一种解决方案

我的jQuery脚本:

<script type='text/javascript'>
  var intval;
  var xmlhttp;
  function init() {
    $('#dialog:ui-dialog').dialog('destroy');
    $('.ui-dialog').dialog({ modal: true, draggable: false, resizable: false, autoOpen: false, open: function(event, ui) { stopTimer(); }, close: function(event, ui) { startTimer(); } });
    $('#targets').dialog({ width: 400, buttons: { 'close': { text: 'Luk', height: '30px', click: function() { $(this).dialog('close'); } }, 'submit': { text: 'OK', class: 'submit', height: '30px', click: function() { $(this).find('form').trigger('submit'); } } } });
    $('#targets" & id2 & "Opener').click(function() { $('#targets').dialog('open'); return false; });
  };
  function startTimer() { intval = setTimeout('ajaxRefresh()', 15000); };
  function stopTimer() { clearTimeout(intval); if(xmlhttp) xmlhttp.abort(); };
  function ajaxRefresh() { xmlhttp = $.ajax({ url: '/', data: {h: 'ok'}, beforeSend: function() { stopTimer(); }, success: function(result) { $('body').html(result); } } }) };
  $(document).ready(function() { init(); startTimer(); $('#targetsFormWrap').parent().appendTo('#targetsForm'); });
</script>

var intval;
var-xmlhttp;
函数init(){
$('#dialog:ui dialog')。dialog('destroy');
$('.ui dialog').dialog({modal:true,draggable:false,resize:false,autoOpen:false,open:function(event,ui){stopTimer();},close:function(event,ui){startTimer();});
$(#targets')。对话框({width:400,按钮:{'close':{text:'Luk',height:'30px',点击:function(){$(this)。对话框('close');}},'submit':{text:'OK',class:'submit',height:'30px',点击:function(){$(this)。查找('form触发器('submit');}});
$(“#目标”&id2&“开启器”)。单击(函数(){($(“#目标”)。对话框('open');返回false;});
};
函数startTimer(){intval=setTimeout('ajaxRefresh()',15000);};
函数stopTimer(){clearTimeout(intval);if(xmlhttp)xmlhttp.abort();};
函数ajaxRefresh(){xmlhttp=$.ajax({url:'/',数据:{h:'ok'},在发送之前:函数(){stopTimer();},成功:函数(result){$('body').html(result);}}}};
$(document).ready(函数(){init();startTimer();$('targetsFormWrap').parent().appendTo('targetsForm');});
HTML:

<div id='targets' class='ui-dialog' title='The Dialog Title' style='text-align: center; display: none;'>
  <form id='targetsForm' name='targetsForm' method='post'>")
    <div id='targetsFormWrap'>")
      <input id='input1target' name='input1target' type='text' value='' style='width: 95%; />
      <input id='input2target' name='input2target' type='text' value='' style='width: 95%; />
      <input id='input3target' name='input3target' type='text' value='' style='width: 95%; />
    </div>
  </form>
</div>

")
")

您正在尝试将targetFormWrap添加到targetsForm,对吗?所以,只要做:

$("#targetsForm").append($("#targetsFormWrap"));

你试过了.append()而不是.appendTo()?我只是试着按照Evan在回答中说的做,但正如我在下面评论的那样,它不起作用了:/现在没有错误,但是表单没有发送输入,所以我想它没有被正确地追加:/我刚刚注意到,如果我使用你的append(),它将文本#targetsFormWrap附加到表单中,而不是id为的div。那么只添加裸文本?工作得很有魅力!:)谢谢你,伙计!