jquery panel加载(dialog加载类似)

项目情况:

  主页面用引用了公共头文件(包含easui.min.js),使用easyui的dialog(href方式)打开窗口(被打开的窗口页面是纯html片段,无body元素等,也引入了公共头文件),结果主页的easyui组件全部异常。

原因:

  easui的dialog是将打开的窗口页面加载到主页中,easui.min.js被加载了两次,组件重复初始化导致异常。

  (dialog是继承panel的)

解决办法:

  将加载的内容放于html的body中,公共头文件放于html的body外面,这样就不在有js的重复加载,问题解决。

总结:

  panel方式(href、url等类似方式)加载页面,正常值加载页面的body部分,这样的话就可以将公共的js和css放于body外面,自定义的js和css放在body里面,加载到主页面后,就不会有js和css冲突了。

主体页面代码:

<%@include file="/framework/common/import-head.jsp"%>

<html>

 <head>

  <title>加载html</title>

 </head>

   <script language="javascript">

       </script>

 <body>

  <button class="customButton" data-option="icon:'reply'" onclick="loadHtml()">加载html</button>

  <div class="easyui-tabs" style="500px;height:250px;">

      <div title="Tab1" style="padding:20px;">

          tab1

      </div>

      <div title="Tab2" style="overflow:auto;padding:20px;">

          tab2

      </div>

      <div title="Tab3" data-options="iconCls:'icon-reload'" style="padding:20px;">

          tab3

      </div>

  </div>

  <div id="loadDiv"></div>

  <script type="text/javascript">

   function loadHtml(){

    var url = "htmlSpec.html";

    //$("#loadDiv").load(url);

    $("#loadDiv").panel({href:url});

   }

  </script>

 </body>

</html>

被加载页面:

<%@include file="/framework/common/import-head.jsp"%>
<html>
 <head>
  <title>被加载html</title>
 </head>
 <body>
  <div class="easyui-tabs" style="500px;height:250px;">
      <div title="help" style="padding:20px;">
          message
      </div>
      <div title="document" style="overflow:auto;padding:20px;">
          somecontext
      </div>
  </div>
 </body>
</html>

原文地址:https://www.cnblogs.com/xtreme/p/5072017.html