我编写了很长一段时间来检查图像(表单,“更新”),直到我把我的输入从type=“提交”改为type=“StructKeyExists”。当图像为“type=”时,IE不发送回控件的名称,而是发送Update.X和Update.Y。
<form method="post">
Old Way:<br />
<input type="submit" value="3" name="Update" /><br />
<input type="submit" value="4" name="Delete" />
<p>New Way:</p>
<input type="image" value="1" name="Update" src="http://www.google.com/intl/en_ALL/images/logo.gif" /><br />
<input type="image" value="2" name="Delete" src="http://images.google.com/intl/en_ALL/images/logos/images_logo_lg.gif" />
</form>我的第一个想法是我应该在我的逻辑中添加两个字符
from: <cfif StructKeyExists(form,"Update")
to: <cfif StructKeyExists(form,"Update.X")但我希望有一个解决方案,可以同时处理type=“提交”和type=“图像”。现在我的逻辑是:
<cfif StructKeyExists(form,"Update") OR StructKeyExists(form,"Update.X")>
<!--- UPDATE table --->
<cfelseif StructKeyExists(form,"Delete") OR StructKeyExists(form,"Delete.Y")>
<!--- DELETE FROM Table --->
</cfif>问:有没有更优雅的方法来检查哪个按钮被按下了?当然,假设表单上有多个按钮,因为如果我只需要检查表单是否已提交,我就会检查form.fieldnames是否存在。
发布于 2009-09-30 20:28:50
您也可以只检查表单域列表,看看它是否包含字符串“Update”。类似于:
<cfif StructKeyExists(form,"fieldnames") and form.fieldnames contains "Update">
<!--- Do Update --->
<cfelseif StructKeyExists(form,"fieldnames") and form.fieldnames contains "Delete">
<!--- Do Delete --->
</cfif>Form.fieldnames包含已提交的表单域的所有名称。
发布于 2009-09-29 02:17:37
要在按钮上有图像的同时获得原始的Form.Update和Form.Delete,请尝试以下操作:
<form action="somewhere" method="post">
<button type="submit" name="Update"><img src="update.btn.png" alt="Update"/></button>
<button type="submit" name="Delete"><img src="delete.btn.png" alt="Delete"/></button>
</form>然后,您将需要CSS来删除默认的按钮样式,以便只获得图像,如下所示:
form button
{
margin : 0;
padding : 0;
border-width : 0;
background : none;
cursor : pointer;
}并确保你在内容的最开始就有一个有效的DOCTYPE,以防止怪癖模式-我通常会抛出一个重置,以确保它是第一件事:
<cfcontent reset/><!DOCTYPE html>发布于 2009-09-29 12:11:31
另一种选择是将图像按钮命名为其他名称,然后简单地添加一个名为Update的隐藏字段来检查它的值。我知道这在某些特殊情况下可能不起作用,你需要检查特定的按钮被点击,但它是一个快速修复,而不需要做任何花哨的图片提交。
https://stackoverflow.com/questions/1490223
复制相似问题