[英]How to get bootstrap select picker click event
我正在使用引導程序選擇器,在其中單擊下拉菜單時需要事件,因為在那之后,我想通過ajax附加一些動態選項,因此我想在用戶單擊下拉列表時顯示警報。 我已經嘗試過下面的代碼,但是它不起作用。
HTML
<select id="new2">
<option>Select Vendor</option>
</select>
腳本代碼
$("select").on("click", function() {
alert("hello");
});
這是引導程序選擇以處理點擊事件的真正解決方案:
$('#new2').on('show.bs.select', function() {
//some code...
});
您必須對選擇框使用onchange()
函數:
$("select").on("change", function() {
alert("hello");
});
您需要將change()
事件用於select
。
$("select").on("change", function() {
alert("hello");
});
另外,您也可以這樣做。
$("select").change(function() {
alert("hello");
});
如果要捕獲選擇函數,則必須使用onchange函數
$("select").on("change", function() {
alert("hello");
});
$("select").on("change", function() {
alert("hello");
});
$("#new2").on("click", function() {
alert("hello");
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.