![](/img/trans.png)
[英]JavaScript: 3 radio buttons, 3rd one has drop down menu and when any are selected have submit button which then gives message
[英]2 drop down boxes with 2 submit buttons, which one was clicked?
我有2個具有相同名稱的下拉框,帶有2個提交按鈕(每個按鈕)
一個出現在頁面的頂部,另一個出現在頁面的底部。 兩者具有相同的功能(我的網格中的“取消”或“更新”記錄)
我有以下代碼:
$(div).on('click', '.action-submit', function (e) {
e.preventDefault();
var action = $(".action-input");
但是,當我做一個:
if (action.val() == "")
並且沒有選擇下拉菜單之一,它沒有通過檢查。 兩者都必須選擇。
如何確定正在使用哪個下拉框? 還是我被迫給它們分別命名並每次都檢查?
如果我正確理解了您的問題,則應該可以使用e.target
。
示例實現如下: 示例Jsfiddle
JS:
$('div').on('click', function(e) {
$(e.target).css('background', 'yellow');
});
HTML:
<div>One div</div>
<div>Another div</div>
var action = $(this);
這樣,您可以檢查單擊的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.