如何在同一个提交按钮中放置onclick和return false语句? [英] How do i put an onclick and a return false statement in the same submit button?

查看:286
本文介绍了如何在同一个提交按钮中放置onclick和return false语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,return false的默认处理方式是:

 < input type =submitonclick = return false/> 

然而,在我的代码中,我想要一个提交按钮运行一个单独的js函数 onclick 这将根据用户选择哪个单选按钮给出ajax输出。



但是由于我使用ajax和我的js函数来处理输出,我希望提交按钮返回false。



但是如果我已经使用 onclick 指向函数:

 < input type =submitonclick =jsfunction()/> 

在哪里可以返回false?



我可以有2 onclick 语句吗?



我想象的另一个选择是如果我知道我是无论函数返回哪个值,都不会提交表单?它应该不是一个提交按钮吗?



但是,如果是这种情况,是否有按钮尝试添加你的方法(jsmethod)我可以在html中的代码看起来像提交一样,但没有提交属性吗?

解决方案

)to your form onsubmit handler like this

 < form onsubmit =jsfunction(); return false;> 

并移除输入的onclick处理程序。

From what i understand, the default treatment for return false is:

<input type="submit" onclick="return false" />

However in my code i would like to have a submit button run a separate js function onclick which will give ajax output based on which radio button the user selected.

But since I'm using ajax and my js function to take care of the output, i want the submit button to return false.

But if i am already using onclick to point to the function:

<input type="submit" onclick="jsfunction()" />

where do i put return false?

Can i have 2 onclick statements?

The other option i would imagine is that if i know i'm not going to be submitting the form regardless of which value the function returns, that it shouldnt be a submit button at all?

But if that's the case, is there a button i can code in html that looks the same as submit but doesnt have the submit property?

解决方案

try to add your method (jsmethod) to your form onsubmit handler like this

<form onsubmit="jsfunction(); return false;">

and remove the input onclick handler.

这篇关于如何在同一个提交按钮中放置onclick和return false语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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