我有一个jsp页面。点击提交评论时,应该会出现一个对话框。这是我的所有代码片段。 JSP代码:
<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 :(得分: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");
});