JavaScript验证——onClick
我有下面一段代码,它在单击删除图像时删除文档JavaScript验证——onClick,javascript,html,validation,Javascript,Html,Validation,我有下面一段代码,它在单击删除图像时删除文档 <tr> To replace the document, you will need to first delete the current one. <form name="delete_attachment_form" action="apr_attachment.cfc?method=delete_apr_attachment" method="post"> <input type=
<tr> To replace the document, you will need to first delete the current one.
<form name="delete_attachment_form" action="apr_attachment.cfc?method=delete_apr_attachment" method="post">
<input type="hidden" name="apr_attachment_id" value="#apr_attachment_id#">
<input type="hidden" name="apr_section_id" value="#apr_section_id#">
<input type="hidden" name="submit_mode" value="DELETE">
<input type="image" name="submit" src="images/delete.gif" alt="DELETE">
</form>
</tr>
要替换文档,您需要先删除当前文档。
现在我想修改它,将图像更改为一个按钮,并放置一些基本的JS验证,以便在删除之前请求确认消息
到目前为止,我把它作为我的代码
<tr> To replace the document, you will need to first delete the current one.
<form name="delete_attachment_form" action="apr_attachment.cfc?method=delete_apr_attachment" method="post">
<input type="hidden" name="apr_attachment_id" value="#apr_attachment_id#">
<input type="hidden" name="apr_section_id" value="#apr_section_id#">
<input type="hidden" name="submit_mode" value="DELETE">
<input type="button" onClick ="return confirm('Are you sure you want to delete the current project activities document')" name="submit" Value="Delete">
</form>
</tr>
要替换文档,您需要先删除当前文档。
但是当我点击这个按钮时,页面没有变化/效果,有人能指出这里发生了什么吗?谢谢将id=“form”
添加到
,然后
<input type="button" onClick ="if(confirm('Are you sure you want to delete the current project activities document')==1){document.getElementById('form').submit();}" name="submit" Value="Delete">
这就是JavaScript的其余部分。。。或者对PHP文件的AJAX调用来为您执行该任务。我可以给你几点建议吗?首先,给出
按钮
元素和ID,比如ID=“deleter”
。然后,要清理内联标记,请在
部分中添加此eventListener:
<script>
var d = document.getElementById('deleter');
var f = document.getElementByName('delete_attachment_form');
d.onClick = function() {
var yn = confirm('Are you sure you want to delete the current project activities document?');
// Note that the 'confirm' dialog is an obsolete construct
if (yn) {
f.submit();
}
};
</script>
var d=document.getElementById('deleter');
var f=document.getElementByName('delete_attachment_form');
d、 onClick=function(){
var yn=confirm('是否确实要删除当前项目活动文档?');
//请注意,“确认”对话框是一个过时的构造
如果(yn){
f、 提交();
}
};
HTML标记
<tr>To replace the document, you will need to first delete the current one.
<form name="delete_attachment_form" action="apr_attachment.cfc?method=delete_apr_attachment" method="post">
<input type="hidden" name="apr_attachment_id" value="#apr_attachment_id#">
<input type="hidden" name="apr_section_id" value="#apr_section_id#">
<input type="hidden" name="submit_mode" value="DELETE">
<input type="button" id="deleter" name="deleter" Value="Delete">
</form>
</tr>
要替换文档,您需要先删除当前文档。
按钮不应该是“提交”类型吗?onClick
的事件监听器在哪里?@DevlshOne难道你看不出来吗?@BoltBait不,没必要我很抱歉,但我是JS新手,我必须为某项任务完成这项工作,我正在尝试摆弄它,同时我正在寻找一个可行的解决方案,我尝试了此操作,但在单击“确定”或“取消”时,文档不会被删除。如果OP的表中有多行,
将不起作用。但是删除文档的操作出现在标记的action元素中,如何在JS脚本中使用它?@user3335993类似于此,我没有提到一个问题。。。如果此表有多行,则每个
元素都需要具有唯一的ID。因此,您可能希望在它们后面加上附件\u id
。然后还必须使用getElementsById
,它创建一个HTML对象列表,并选择要处理的对象。