简体   繁体   English

如何检查哪个按钮被打勾jquery / html

[英]How to check which button is ticked jquery/html

I'm quiet new to jquery and html. 我对jquery和html很陌生。 I'm facing an issue right now on how to save the value based on which button is ticked. 我现在面临一个问题,即如何根据勾选的按钮保存值。

Scenario is: 场景是:

  1. I have a big formregister.tpl where one of the fields is price . 我有一个很大的formregister.tpl ,其中一个字段是price This price is automatically computed and shown in the registration form which the user can manually change. 该价格自动计算并显示在用户可以手动更改的注册表中。

  2. I have also formregister.js where the computation of the value for field price is done. 我还有formregister.js ,其中计算了场价的价值。 Also, i have created a pop-up box (dialogbox.tpl) that pops when the value of automated calculation is different from what the user entered. 另外,我还创建了一个弹出框(dialogbox.tpl) ,当自动计算的值与用户输入的值不同时,该框就会弹出。 This has 2 buttons which ask the user which one to save, the auto calculated value or the value he entered. 这有2个按钮,询问用户保存哪一个,自动计算值或他输入的值。

I don't want to pass value to dialogbox.tpl because the parent form already has the 2 values, so want to manipulate it from there. 我不想将值传递给dialogbox.tpl因为父窗体已经具有2个值,因此想从那里进行操作。

Question: 题:

Is it possible to check from the formregister.tpl which button is ticked in the dialogbox.tpl ? 是否有可能从检查formregister.tpl该按钮在勾选dialogbox.tpl

I have searched the web already but unable to find similar scenarios. 我已经在网上搜索过,但是找不到类似的情况。

Please let me know any related links that might help me. 请告诉我任何可能对我有帮助的相关链接。

Thank you so much for your help. 非常感谢你的帮助。

If you give your submit buttons a name and a value. 如果您为提交按钮指定一个名称和一个值。

<input name="button1" type="submit" value="Button 1" />
<input name="button2" type="submit" value="Button 2" />

button1 or button2 will be passed via GET or POST. button1或button2将通过GET或POST传递。

Or you can do it with onclick 或者您可以使用onclick

<input id="button1" 
       onclick="yourFunction(this);" 
       name="button1" 
       type="submit" 
       value="Button 1" />
<input id="button2" 
       onclick="yourFunction(this);" 
       name="button2" 
       type="submit" 
       value="Button 2" />

then you can check the ID in your function: 然后你可以检查你的功能中的ID:

function yourFunction (button) {
    var yourButton = jQuery(button).attr('id');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM