我在我的项目中使用 YUI 2.7.0 和 Struts,并且有一个带有两个提交按钮的表单。一个用于保存,另一个用于删除。表单提交给 DispatchAction。我已经成功添加了 onclick 监听器,但问题是表单在监听器执行之前提交。我需要在表单提交之前设置调度参数。我该怎么做呢?以下是我到目前为止的内容:
<form name="adminUserForm" method="post" action="manage_user.do">
<input type="hidden" id="dispatch" name="dispatch" value="unspecified"/>
<!-- other form fields here -->
<input type="submit" value="Save User" id="saveUser">
<input type="submit" value="Delete User" id="deleteUser">
</form>
<script type="text/javascript">
function confirmDelete(msg)
{
if (confirm(msg))
{
return setDispatchMethod("delete");
}
else
return false;
}
function setDispatchMethod(methodName)
{
dispatchField = document.getElementById("dispatch");
dispatchField.value = methodName
return true;
}
var onClickSaveUser = function (e)
{
return setDispatchMethod('save');
};
var onClickDeleteUser = function (e)
{
return confirmDelete('Are you sure you want to delete the user?');
};
new YAHOO.widget.Button("deleteUser", {onclick: {fn: onClickDeleteUser }});
new YAHOO.widget.Button("saveUser", {onclick: {fn: onClickSaveUser }});
</script>