简体   繁体   English

2个带有2个提交按钮的下拉框,单击了哪个?

[英]2 drop down boxes with 2 submit buttons, which one was clicked?

I have 2 drop down boxes with the same name with 2 submit buttons (for each) 我有2个具有相同名称的下拉框,带有2个提交按钮(每个按钮)

One appears at the top of the page and the other appears at the bottom. 一个出现在页面的顶部,另一个出现在页面的底部。 Both have the same function ("Cancel" or "Update" records in my grid) 两者具有相同的功能(我的网格中的“取消”或“更新”记录)

I have this code: 我有以下代码:

$(div).on('click', '.action-submit', function (e) {
    e.preventDefault();
    var action = $(".action-input");

However when I do a: 但是,当我做一个:

if (action.val() == "")

And one of the drop downs aren't selected, it fails the check. 并且没有选择下拉菜单之一,它没有通过检查。 Both have to be selected. 两者都必须选择。

How can I determine which drop down box is being worked with? 如何确定正在使用哪个下拉框? Or am I forced to give them separate names and check for both everytime? 还是我被迫给它们分别命名并每次都检查?

If I understood your question correctly, you should be able to just use e.target . 如果我正确理解了您的问题,则应该可以使用e.target

Sample implementation is as follows: Sample Jsfiddle 示例实现如下: 示例Jsfiddle

JS: JS:

$('div').on('click', function(e) {
    $(e.target).css('background', 'yellow');
});

HTML: HTML:

<div>One div</div>
<div>Another div</div>
var action = $(this);

这样,您可以检查单击的内容。

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

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