我可以弹出一个带有空html表单的jQuery对话框。
但是现在,我想弹出一个带有带参数的html表单的jQuery对话框。
代码:
触发jQuery对话框的按钮(JSP代码):
<input id="update_button" type="button" value="Edit" onclick="UpdateFunction('<%=category.getTag()%>');" />用于对话的脚本:
<head>
<script>
function UpdateFunction(tag) {
alert(tag); // I can get this parameter correctly
$( "#update_category" ).dialog( "open" );
}
$(document).ready(function(){
$( "#update_category" ).dialog({
autoOpen: false,
width: 600
});
});
</script>
</head>HTML表单代码(它涉及最初在“表单操作”中的GAE代码,我删除了它以澄清这个问题):
<body>
<%
String categoryTag = request.getParameter("categoryTag");
// curCategory will be derived from categoryTag
%>
<div id="update_category">
<form id="categoryForm" name="categoryForm">
<table>
<tr>
<td>Tag : </td>
<td><input type="text" name="categoryTag" style="color:#888;" value="<%= curCategory.getTag() %>" readonly /></td>
</tr>
<tr>
<td>Title : </td>
<td><input type="text" name="categoryTitle" value="<%= curCategory.getTitle() %>" /></td>
</tr>
</table>
</form>
</div>
</body>问题是:
目前会先执行body中的代码,这样"String categoryTag“在下面的代码中会变成null
<%
String categoryTag = request.getParameter("categoryTag");
// curCategory will be derived from categoryTag
%>这将导致稍后的NullPointerException。
那么怎样才能弹出一个带有参数表单的jQuery对话框呢?
提前谢谢。
埃里克
发布于 2014-08-05 13:29:14
而不是调用单独的.dialog( "open" )函数。你可以把它写成,
<script>
function UpdateFunction(tag) {
alert(tag); // I can get this parameter correctly
var dialog_text=tag;
$("#update_category").empty();
$("#update_category").append(dialog_text);
$( "#update_category" ).dialog({
autoOpen: false,
width: 600
//Handle your button events for the dialog.
});
}
</script>https://stackoverflow.com/questions/25131023
复制相似问题