一个按钮触发另一个按钮点击事件 [英] One button firing another buttons click event

查看:1133
本文介绍了一个按钮触发另一个按钮点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在表单上填写两个提交按钮,其中一个是我的团队建设,一个在上面,另一个在下面。我收到了来自我的技术团队的关于添加它的投诉,因为它需要一些服务器端编码以确保用户不会多次点击它。显然他们有一个按钮,但要补充的是验证两个将是一个问题。



你不能只是调用按钮相同的东西,具有相同的ID和该表单不会将其视为一个按钮吗?

我认为另一个选项是新按钮即使在另一个按钮上也会触发点击。然后,他们仍然只需点击一下即可,但我得到了两个按钮。如何写这个?



感谢,
Adma

解决方案

我只熟悉ASP.net和C#按钮,但使用C#可以将两个不同的按钮连接到相同的单击事件处理程序。您也可以通过使用次按钮触发主按钮单击事件来完成客户端。这里有一个非常简单的例子:

HTML

 <输入类型=buttonid =primaryButtononclick =ExistingLogic()/> 
< input type =button
id =secondaryButton
onclick =document.getElementById('primaryButton')。click()/>


I'd like two submit buttons on a form i have my team building, one above the fold, and one below. I'm getting complaints from my tech team about adding it because it requires some server side coding to make sure the user doesn't click it more than once. Apparently they have it one button, but to add that validation to two would be a problem.

Can you not just call the button the same thing, with the same ID and wouldn't the form treat it as one button?

Another option I thought would be for new button to fire a click even on the other button. Then they still have one click even for the form, but I get my two buttons. How would I write that?

Thanks, Adma

解决方案

I'm only familiar with ASP.net and C# buttons, but using C# you could wire two different buttons to the same click event handler. You could also do it client side by triggering the primary buttons click event with your secondary button. Here's a VERY simple example:

HTML

<input type="button" id="primaryButton" onclick="ExistingLogic()" />
<input type="button" 
       id="secondaryButton" 
       onclick="document.getElementById('primaryButton').click()" />

这篇关于一个按钮触发另一个按钮点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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