使用jquery easyui dialog 加載遠程頁面時,遠程頁面有CKEDITOR等需要調用JS,解決方案:

jquery easyui dialog 有一個onLoad方法,在遠程加載時調用,我們利用這個解決該問題。

在調用的那個父頁面上書寫所用的js方法,子頁面上只有<body>內容即可:

實例:

子頁面:

<html>
  <head>
    <base href="${ctx }">
    
    <title>My JSP 'addOrEditPersonalArticle.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
  
  <body>
  <center>
      <form id="personalForm">
      <table bordercolor="#121010" border="1" cellpadding="0" cellspacing="0" width="700px">
      <tr>
      <td nowrap="nowrap">*文章標題:</td>
      <td>
      <input type="text" name="title" id="title" value="${article.title }" style="width:450px"/>
      <input type="hidden" name="id" id="id" value="${article.id }"/>
      </td>
      </tr>
      <tr>
      <td nowrap="nowrap">*是否發佈:</td>
      <td>
      <input type="radio" name="articleStatus" id="articleStatusYes" <c:if test="${article.articleStatus ==3 }">checked="checked"</c:if> value="3"/>是
      <input type="radio" name="articleStatus" id="articleStatusNo" <c:if test="${article.articleStatus !=3 and article.articleStatus != null}">checked="checked"</c:if> value="0"/>否
      </td>
      </tr>
      <tr>
      <td nowrap="nowrap">*是否置頂:</td>
      <td>
      <input type="radio" name="top" id="topYes" <c:if test="${article.top ==1 }">checked="checked"</c:if> value="1"/>是
      <input type="radio" name="top" id="topNo" <c:if test="${article.top ==0 }">checked="checked"</c:if> value="0"/>否
      </td>
      </tr>
      <tr align="center">
      <td colspan="2">
      <textarea name="content" id="content">${article.content }</textarea>
      </td>
      </tr>
      <tr>
      <td>備註:</td>
      <td>
      <textarea name="" style="width: 500px"></textarea>
      </td>
      </tr>
      </table>
      </form>
      </center>
  </body>
</html>

父頁面:

<html>
<head>
<base href="${ctx}">
    
   <title>My JSP 'personalArticleList.jsp' starting page</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="${ctx}/jsp/resource/js/ckeditor3.6.2/ckeditor.js"></script>
<script type="text/javascript" src="${ctx}/jsp/resource/js/ckfinder/ckfinder.js"></script>
<%@ include file="/jsp/include/resource.jsp"%>
<script>

       //新增Or修改個人專欄文章
       function addOrEditPersonalArticle(index,id,obj){
 
        $("#addArticleDiv").dialog({
        title: '新增文章',    
   width: 900,    
   height: 500,    
   closed: false,    
   cache: false,    
   href: '${ctx}/toAddOrEditPersonalArticleView.do?id='+id,    
   modal: true,
   toolbar:[{
    text:'保存',
iconCls:'icon-edit',
handler:function(){
alert($("input[name='articleStatus']:checked").val());
if($("#title").val()==null||$("#title").val()==''){
$.messager.alert('提示框','文章標題不能爲空!');
return ;
}else if($("input[name='articleStatus']:checked").val()==null||$("input[name='articleStatus']:checked").val()==''){
$.messager.alert('提示框','是否發佈不能爲空!');
return ;
}else if($("input[name='top']:checked").val()==null||$("input[name='top']:checked").val()==''){
$.messager.alert('提示框','是否置頂不能爲空!');
return ;
}
$("#content").val(CKEDITOR.instances.content.getData());
$.ajax({
url:'${ctx}/savePersonalArticle.json',
type:'post',
data:$("#personalForm").serialize(),
dataType:'json',
success:function(data){
$.messager.alert('提示框',data.message);
$("#addArticleDiv").dialog('close');
$("#dg").datagrid("loadData",data);
}
});
}
   },{
    text:'返回',
iconCls:'icon-edit',
handler:function(){
//window.location.href="${ctx}/findPersonalArticleListView.do";
      $("#addArticleDiv").dialog('close');
}
   },{
    text:'批量替換圖片',
iconCls:'icon-edit',
handler:function(){
replacePic();
}
   }],
   onLoad:function(){
    var editor = null;
       editor = CKEDITOR.replace( 'content', {
           customConfig:'${ctx}/jsp/resource/js/ckeditor3.6.2/config.js'
       });
       CKFinder.setupCKEditor( editor, '${ctx}/jsp/resource/js/ckfinder/' );
   }
        });
       }
       
</script>
</head>

<body>

<div >
<!-- 查詢和按鈕框 -->
<table width="95%">
<tr align="right">
<td><input type="button" onclick="addOrEditPersonalArticle(null,null,null)" value="新增個人文章"/></td>
</tr>
</table>
</div>
<div > 
<!-- 個人放置的內容 -->
<table id="dg">
</table>
<div id="addArticleDiv"></div>
</div>

</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章