我有4個按鈕,我希望能夠檢測哪個按鈕被點擊或標籤,並與空格鍵一起選擇。我無法讓我的按鈕提醒。有人會幫我檢測哪個按鈕被選中了嗎?jQuery點擊或選擇通知按鈕被選擇
<div id="searchoptions">
<div class="col-sm-3">
<button type="button" class="btn-u btn-default input-sm margin-bottom-10" id="accountNumber" name="accountNumber" value="accountNumber">PROPERTY ID</button>
</div>
<div class="col-sm-3">
<button type="button" class="btn-u btn-default input-sm margin-bottom-10" id="name" name="name" value="name">OWNER NAME</button>
</div>
<div class="col-sm-3">
<button type="button" class="btn-u btn-default input-sm margin-bottom-10" id="location" name="location" value="location">PROPERTY ADDRESS</button>
</div>
<div class="col-sm-3">
<button type="button" class="btn-u btn-default input-sm margin-bottom-10" id="billingAddress" name="billingAddress" value="billingAddress">BILLING ADDRESS</button>
</div>
</div>
$(document).on('click', '#accountNumber, #name, #location, #billingAddress,', function() {
var value = $(this).val();
alert(value);
if (value === "accountNumber") {
alert("accountNumber");
} else if (value === "name"){
alert("name");
} else if (value === "location"){
alert("location");
} else if (value === "billingAddress"){
alert("billingAddress");
}
});
也試過:
$('input[type=button]').each(function(){
var value = $(this).val();
if (value === "accountNumber") {
alert("accountNumber");
} else if (value === "name"){
alert("name");
} else if (value === "location"){
alert("location");
} else if (value === "billingAddress"){
alert("billingAddress");
}
});
問題是在選擇器字符串'#billingAddress'後面的逗號, – guest271314