• <bdo id='g3EdO'></bdo><ul id='g3EdO'></ul>
  • <i id='g3EdO'><tr id='g3EdO'><dt id='g3EdO'><q id='g3EdO'><span id='g3EdO'><b id='g3EdO'><form id='g3EdO'><ins id='g3EdO'></ins><ul id='g3EdO'></ul><sub id='g3EdO'></sub></form><legend id='g3EdO'></legend><bdo id='g3EdO'><pre id='g3EdO'><center id='g3EdO'></center></pre></bdo></b><th id='g3EdO'></th></span></q></dt></tr></i><div id='g3EdO'><tfoot id='g3EdO'></tfoot><dl id='g3EdO'><fieldset id='g3EdO'></fieldset></dl></div>
    <tfoot id='g3EdO'></tfoot>

    1. <legend id='g3EdO'><style id='g3EdO'><dir id='g3EdO'><q id='g3EdO'></q></dir></style></legend>

      <small id='g3EdO'></small><noframes id='g3EdO'>

      1. struts2、ajax 和注入的 jquery 标签

        struts2, ajax and injected jquery tag(struts2、ajax 和注入的 jquery 标签)
      2. <legend id='BV8wq'><style id='BV8wq'><dir id='BV8wq'><q id='BV8wq'></q></dir></style></legend>
        <tfoot id='BV8wq'></tfoot>

          <tbody id='BV8wq'></tbody>
            • <bdo id='BV8wq'></bdo><ul id='BV8wq'></ul>
                1. <small id='BV8wq'></small><noframes id='BV8wq'>

                  <i id='BV8wq'><tr id='BV8wq'><dt id='BV8wq'><q id='BV8wq'><span id='BV8wq'><b id='BV8wq'><form id='BV8wq'><ins id='BV8wq'></ins><ul id='BV8wq'></ul><sub id='BV8wq'></sub></form><legend id='BV8wq'></legend><bdo id='BV8wq'><pre id='BV8wq'><center id='BV8wq'></center></pre></bdo></b><th id='BV8wq'></th></span></q></dt></tr></i><div id='BV8wq'><tfoot id='BV8wq'></tfoot><dl id='BV8wq'><fieldset id='BV8wq'></fieldset></dl></div>
                  本文介绍了struts2、ajax 和注入的 jquery 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用带有 struts2-jQuery-plugin 的 Struts 2.3.

                  I am using Struts 2.3 with struts2-jQuery-plugin.

                  我必须使用 ajax 动态加载一个动作的结果.
                  在 JSP 中有一些普通的 html 和一个 jQuery 标记

                  I have to load dynamically with ajax a result from an action.
                  In the JSP there is some normal html and a jQuery tag

                  <sj:datepicker cssClass="dataScadenzaDiv" id="dataScadenzaDiv"
                          name="dataScadenza" maxDate="-1d" label="data scadenza"  theme="xhtml"/>
                  

                  一切正常,注入ajax的代码是:

                  All works OK and the code injected with ajax is:

                  <!-- lotto dpi -->
                  <tr>
                  <td class="tdLabel"><label for="lotto" class="label">Lotto:</label></td>
                  <td><input type="text" name="txtLotto" size="15" value="" id="lotto"/></td>
                  </tr>
                  
                  <!-- tGestDataScadenza -->
                  <div id="dataScadenzaAjax"></div>
                  <input type="text" name="dataScadenza" value="" id="dataScadenzaDiv"     class="dataScadenzaDiv" theme="xhtml"/><script type='text/javascript'>
                  jQuery(document).ready(function () {
                  jQuery.struts2_jquery_ui.initDatepicker(false);
                  });
                  jQuery(document).ready(function () {
                  var options_dataScadenzaDiv = {};
                  options_dataScadenzaDiv.showOn = "both";
                  options_dataScadenzaDiv.buttonImage = "/RadioFrequenza2/struts     /js/calendar.gif";
                  options_dataScadenzaDiv.maxDate = "-1d";
                  options_dataScadenzaDiv.jqueryaction = "datepicker";
                  options_dataScadenzaDiv.id = "dataScadenzaDiv";
                  options_dataScadenzaDiv.name = "dataScadenza"; jQuery.struts2_jquery_ui.bind(jQuery('#dataScadenzaDiv'),options_dataScadenzaDiv    );
                  
                  });
                  </script>
                  

                  但现在 <input type="text" name="dataScadenza"> 呈现为普通文本和点作为日期选择器.
                  我认为注入的javascript没有执行...

                  but now <input type="text" name="dataScadenza"> is rendered as a normal text and dot as a datepicker.
                  I think that the injected javascript is not executed...

                  我能做什么?

                  推荐答案

                  问题是struts2-jQuery-plugin正在生成一个脚本,该脚本会在DOM准备好后运行:jQuery(document).ready(function() { ...

                  The problem is that struts2-jQuery-plugin is generating a script that will run after the DOM is ready: jQuery(document).ready(function () { ...

                  页面被渲染后,ready 事件被触发.但是在 AJAX 调用之后,就不是了.

                  After the page is rendered, the ready event is fired. But after an AJAX call, it is not.

                  那么你有两个解决方案:

                  Then you have two solutions:

                  1. 避免对 AJAX 返回的 JSP 片段使用 struts2-jquery-plugin;改用纯 jQuery 并避免使用 jQuery(document).ready(function () {
                    (但我想它不会完全可靠);

                  使用一个技巧来覆盖默认的 jQuery 就绪事件,如此出色答案中所述,以便就绪函数将变为可触发的.
                  然后将其作为 AJAX 返回的 JSP 片段的最后一行触发

                  use a trick to override the default jQuery ready event, as described in this great answer, so that the ready function will become triggerable.
                  Then trigger it as last row of your JSP snippet returned by AJAX

                  <sj:datepicker cssClass="dataScadenzaDiv" id="dataScadenzaDiv"
                                 name="dataScadenza"        maxDate="-1d" 
                                 label="data scadenza"      theme="xhtml"/>
                  <script>
                       $.triggerReady();
                  </script>
                  

                  我制作了一个小提琴来展示这个技巧,并在 jQuery 1.10.1 中对其进行了测试:

                  I've made a fiddle showing the trick, and tested it in jQuery 1.10.1:

                  运行演示

                  HTML

                  <input type = "button" 
                        value = "trigger ready event" 
                      onclick = "$.triggerReady();" />
                  

                  JAVASCRIPT

                  // Overrides jQuery-ready and makes it triggerable with $.triggerReady
                  // This script needs to be included before other scripts using the jQuery-ready.
                  // Tested with jQuery 1.10.1
                  (function(){
                  var readyList = [];
                  
                  // Store a reference to the original ready method.
                  var originalReadyMethod = jQuery.fn.ready;
                  
                  // Override jQuery.fn.ready
                  jQuery.fn.ready = function(){
                  if(arguments.length && arguments.length > 0 && typeof arguments[0] === 'function') {
                    readyList.push(arguments[0]);
                  }
                  
                  // Execute the original method.
                  originalReadyMethod.apply( this, arguments );
                  };
                  
                  // Used to trigger all ready events
                  $.triggerReady = function() {
                    $(readyList).each(function(){this();});
                  };
                  })();
                  
                  
                  /* This part is for demo only and should be removed */
                  $( document ).ready(function(){
                      alert('document.ready is fired!');
                  });
                  

                  请记住,最初在 ready 事件中运行的其他处理程序也会再次触发,因此请谨慎使用.

                  Remember that also the other handlers originally run in ready event will be triggered again, so use this with caution.

                  这篇关于struts2、ajax 和注入的 jquery 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  JavaScript/jQuery: How to make sure cross-domain click tracking event succeeds before the user leaves the page?(JavaScript/jQuery:如何在用户离开页面之前确保跨域点击跟踪事件成功?)
                  how to redirect to struts action from java script in struts 2?(如何从struts 2 中的java 脚本重定向到struts 动作?)
                  HOWTO do CSRF protection in Struts2 application for AJAX requests(如何在 Struts2 应用程序中为 AJAX 请求做 CSRF 保护)
                  Send JSON object to Struts 2 action by using strut2 jquery plugin tags(使用 strut2 jquery 插件标签将 JSON 对象发送到 Struts 2 操作)
                  upload file in struts2 using ajax(使用ajax在struts2中上传文件)
                  HTTP Array Parameters with Struts 2 via an Ajax Call(通过 Ajax 调用使用 Struts 2 的 HTTP 数组参数)
                    <bdo id='YLMFG'></bdo><ul id='YLMFG'></ul>

                    1. <legend id='YLMFG'><style id='YLMFG'><dir id='YLMFG'><q id='YLMFG'></q></dir></style></legend>

                        <tbody id='YLMFG'></tbody>
                          <tfoot id='YLMFG'></tfoot>

                          • <small id='YLMFG'></small><noframes id='YLMFG'>

                          • <i id='YLMFG'><tr id='YLMFG'><dt id='YLMFG'><q id='YLMFG'><span id='YLMFG'><b id='YLMFG'><form id='YLMFG'><ins id='YLMFG'></ins><ul id='YLMFG'></ul><sub id='YLMFG'></sub></form><legend id='YLMFG'></legend><bdo id='YLMFG'><pre id='YLMFG'><center id='YLMFG'></center></pre></bdo></b><th id='YLMFG'></th></span></q></dt></tr></i><div id='YLMFG'><tfoot id='YLMFG'></tfoot><dl id='YLMFG'><fieldset id='YLMFG'></fieldset></dl></div>