JavaScript验证 - onClick [英] JavaScript validation-- onClick

查看:90
本文介绍了JavaScript验证 - onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下一段代码,当删除图像被点击时删除一个文档

 < tr>要替换文档,您需要先删除当前文档。 
< input type =hiddenname =apr_attachment_idvalue =#apr_attachment_id#>
< input type =hiddenname =apr_section_idvalue =#apr_section_id#>
< input type =hiddenname =submit_modevalue =DELETE>
< input type =imagename =submitsrc =images / delete.gifalt =DELETE>
< / form>
< / tr>

现在我想修改它并将图像更改为一个按钮,并将一些基本的JS验证它会在删除前询问确认信息。



我已将此作为我的代码到目前为止

 < TR>要替换文档,您需要先删除当前文档。 
< input type =hiddenname =apr_attachment_idvalue =#apr_attachment_id#>
< input type =hiddenname =apr_section_idvalue =#apr_section_id#>
< input type =hiddenname =submit_modevalue =DELETE>
< input type =buttononClick =return confirm('您确定要删除当前项目活动文档')name =submitValue =Delete>
< / form>
< / tr>

但是当我点击这个按钮时页面没有变化/效果,任何人都可以指出什么在这里发生?谢谢

解决方案

id =form添加到< form> ,然后

 < input type =buttononClick = if(confirm('你确定要删除当前项目活动文档')== 1){document.getElementById('form')。submit();}name =submitValue =Delete> ; 


I have the following piece of code which deletes a document when the delete image is clicked

<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>   

Now I want to modify this and change the image to a button and put some basic JS validation so that it asks a confirmation message before deleting.

I have this as my code so far

<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>   

But there is no change/effect in the page when I click this button, Can anyone point out whats happening here? Thanks

解决方案

Add id="form" to <form>, then

<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验证 - onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆