2015-12-07 20 views
1

我有一個場景,點擊一個按鈕後,我打開一個jQuery對話框,通過ajax調用呈現一個jsp(struts)表單,如下所示。該表格有一個<sj:select>標籤,它接收來自對象List的條目。該列表正確填充,但它不會顯示在對話框上,而是顯示在我打開對話框的父級jsp頁面上。 這裏是我的父JSP代碼:<sj:select>不工作在jQuery對話框

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> 

$("#mydialogpopup").click(function(){ 
    $.ajax({ 
     url : "popupAjax.action", 
     success : function(response) { 
      $("#form_add").html(response); 
     $("#form_add").dialog('open'); 
     } 
}); 
}); 
    $("#form_add").dialog({autoOpen: false, 
     modal: true, 
     width: 450, 
     height: 280 
    }); 

</script> 


><a href="#" id="mydialogpopup" class="isw-plus"></a> 

<div class="newdialog" id="form_add" style="display: block;" title="My Dialog"></div> 

下面是其呈現爲Ajax調用的一個成功的結果,我popup.jsp頁面的代碼:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<%@ taglib uri="/struts-tags" prefix="s"%>  
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%> 

<html> 
<head> 
<sj:head/> 
<link href="jsp/css/stylesheets.css" rel="stylesheet" type="text/css" /> 
</head> 

    <s:form id="userForm" action="" method="post" > 

    <s:url id="remoteurl" action="listUser"/>       
          <sj:select 
          href="%{remoteurl}" 
          id="echo3" 
          cssStyle="width: 100%;" 
          name="echo" 
          list="userList" 
          listKey="id" 
          listValue="name" 
          autocomplete="true" 
          emptyOption="true" 
          headerKey="-1" 
          loadMinimumCount="2" 
          headerValue="Please Select a User" /> 

    <sj:submit targets="result" id="savedialog" value="Save" validate="true"/>&nbsp; &nbsp; <input type="button" id="closedialog" value="Cancel"/> 

    </s:form> 

回答

0

不要在兩次加載jQuery庫同一頁。第一次用

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> 

加載你

<sj:head/> 

加載第二次同樣,你不應該渲染頁面

<html> 
<head> 
<sj:head/> 
<link href="jsp/css/stylesheets.css" rel="stylesheet" type="text/css" /> 
</head> 

的頁面渲染上使用這些標籤不是一個完整的html頁面,而是一個完整的html頁面,你只應該渲染適合父標籤正文的標籤。由於您渲染到div標記,因此它的位置由CSS樣式定義,並可能會浮出對話框。確保你使用position: relative風格。

+0

感謝您的回覆..我更正了代碼,但仍然無法正常工作。在做了更多的研究後,我發現它是struts中的一個缺陷..這裏的鏈接:https://code.google.com/p/struts2-jquery/issues/detail?id = 1022 –