2015-04-06 107 views
4

我有一個jsp頁面。點擊提交審查對話框應該來。這是我所有的代碼片段。 JSP代碼:jquery對話框不工作

<td align="left"> 
     <span> 
     <div id="rate" class="rate" style="" title="Rate">Submit Review</div> 
     </span> 
     <div id="rateDialog" class="rateDialog" style="display:none;" title="Rating"> 
     <div id="showDialogMessage"></div> 
     <label>Rate your overall satisfaction:</label> 
     <input type="radio" name="rating" value="1" class="star"/> 
     <input type="radio" name="rating" value="2" class="star"/> 
     <input type="radio" name="rating" value="3" class="star"/> 
     <input type="radio" name="rating" value="4" class="star"/> 
     <input type="radio" name="rating" value="5" class="star"/> 
     <label>Please provide your review: </label> 
     <textarea name="reviewArea" rows="5"></textarea> 
     <input id="submit" type="submit" value="Submit" style="margin : 18px 0px 0px 93px;"/> 

     </div> 

     </td> 

JS代碼:

<script> 
$(document).ready(function() { 
$(function() { 
$("#rateDialog").dialog({ 
autoOpen: false, 
open: function(event, ui) { 
    $("#showDialogMessage").hide(); 
    $('#reviewArea').val(''); 
    } 
}); 
$("#rate").on("click", function() { 
$("#rateDialog").dialog("open"); 
}); 
}); 
// Validating Form Fields..... 
$("#submit").click(function(e) { 
$("#showDialogMessage").hide(); 
    var xmlhttp; 
    $("#submit").prop('disabled',true); 
    alert("called"); 
     var url=""; 
     if (window.XMLHttpRequest) 
     { 
      xmlhttp=new XMLHttpRequest(); 
     } 
     else 
     { 
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
     } 
     xmlhttp.onreadystatechange=function() 
     { 

      if (xmlhttp.readyState==4 && xmlhttp.status==200) 
      { 
       $("#submit").removeAttr('disabled'); 
       document.getElementById("showPasswordMessage").innerHTML=xmlhttp.responseText; 
       $("#showPasswordMessage").show(); 
      } 
     } 

     xmlhttp.open("GET", url, true); 
     xmlhttp.send(); 
}); 
}); 

上點擊提交審覈其顯示的錯誤。我是一名初學者。任何幫助將不勝感激

Error: cannot call methods on dialog prior to initialization; attempted to call method 'open' 
+0

太謝謝你了:)它的工作! – user3681970 2015-04-06 10:09:57

回答

3

這裏是你應該做的:

// Instanciate the dialog 
var rateDialog = $("#rateDialog").dialog({ 
autoOpen: false, 
open: function(event, ui) { 
    $("#showDialogMessage").hide(); 
    $('#reviewArea').val(''); 
    } 
}); 

$("#rate").on("click", function() { 
    // Display the dialog 
    rateDialog.dialog("open"); 
}); 
+0

謝謝先生!此問題已解決。但我堅持另一個問題。我有一張桌子。對話框僅適用於第一個單元格。如果我點擊第二行的提交評論,對話框不會出現:( – user3681970 2015-04-06 10:26:42

+1

你對每行都使用'id =「rate」'',你必須使用一個類並相應地更改你的代碼。將答案設置爲已解決。 – 2015-04-06 10:30:27