2015-04-06 113 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