I'm using Chosen jQuery plugin and noticed that the change
event is working only when the page loads, NOT every time the input
field is being change.
我正在使用Chosen jQuery插件,并注意到更改事件仅在页面加载时才起作用,而不是每次输入字段都在更改时。
How can I make it work every time the user changes the value of the input field?
每次用户更改输入字段的值时,如何使其工作?
Here is my code:
这是我的代码:
$("#day").chosen().change({
console.log('working');
});
Am I missing something?
我错过了什么吗?
5 个解决方案
#1
16
To fire the standard change event, use like:
要触发标准更改事件,请使用如下:
$('#day').on('change', function(e) {
// triggers when whole value changed
console.log("value changed");
});
To fire the event on each key press,
要在每个按键上发射事件,
$('#day').on('keyup', function(e) {
// triggers when each key pressed
console.log("key pressed");
});
To know about the default events of chosen, refer here.
要了解所选的默认事件,请参阅此处。
#2
15
Try this:
尝试这个:
$(document).ready(function(){
$("selector").chosen().change(function(){
var id = $(this).val();
});
})
#3
5
Updating Chosen Dynamically
动态更新选择
If you need to update the options in your select field and want Chosen to pick up the changes, you'll need to trigger the "chosen:updated" event on the field. Chosen will re-build itself based on the updated content.
如果您需要更新选择字段中的选项并希望选择选择更改,则需要在该字段上触发“selected:updated”事件。 Chosen将根据更新的内容重新构建自己。
$("#foo").trigger("chosen:updated");
#4
1
Then Write it in keyup event of input:
然后在输入的keyup事件中写入:
$('inputselector').keyup(function() {
$("#day").chosen().change({
console.log('working');
});
});
and on dom ready:
并准备好了:
$('inputselector').trigger('keyup');
#5
0
//Asp.net dropdown listbox
<asp:ListBox ID="CompanySelect" runat="server" AppendDataBoundItems="true"
AutoPostBack="true"
data-placeholder="Select Companies" class="chosen-select" SelectionMode="Multiple"
EnableViewState="true" Height="39px" Width="99%" >
<asp:ListItem Value="0">All</asp:ListItem>
</asp:ListBox>
//This code help me for hiting chozen change event.
$('#chosen').val('').change()
{
alert("working");
}
//if you want to get select value you need to do this.
$('#chosen').val('').change()
{
alert($(".chosen-select").val());
}
#1
16
To fire the standard change event, use like:
要触发标准更改事件,请使用如下:
$('#day').on('change', function(e) {
// triggers when whole value changed
console.log("value changed");
});
To fire the event on each key press,
要在每个按键上发射事件,
$('#day').on('keyup', function(e) {
// triggers when each key pressed
console.log("key pressed");
});
To know about the default events of chosen, refer here.
要了解所选的默认事件,请参阅此处。
#2
15
Try this:
尝试这个:
$(document).ready(function(){
$("selector").chosen().change(function(){
var id = $(this).val();
});
})
#3
5
Updating Chosen Dynamically
动态更新选择
If you need to update the options in your select field and want Chosen to pick up the changes, you'll need to trigger the "chosen:updated" event on the field. Chosen will re-build itself based on the updated content.
如果您需要更新选择字段中的选项并希望选择选择更改,则需要在该字段上触发“selected:updated”事件。 Chosen将根据更新的内容重新构建自己。
$("#foo").trigger("chosen:updated");
#4
1
Then Write it in keyup event of input:
然后在输入的keyup事件中写入:
$('inputselector').keyup(function() {
$("#day").chosen().change({
console.log('working');
});
});
and on dom ready:
并准备好了:
$('inputselector').trigger('keyup');
#5
0
//Asp.net dropdown listbox
<asp:ListBox ID="CompanySelect" runat="server" AppendDataBoundItems="true"
AutoPostBack="true"
data-placeholder="Select Companies" class="chosen-select" SelectionMode="Multiple"
EnableViewState="true" Height="39px" Width="99%" >
<asp:ListItem Value="0">All</asp:ListItem>
</asp:ListBox>
//This code help me for hiting chozen change event.
$('#chosen').val('').change()
{
alert("working");
}
//if you want to get select value you need to do this.
$('#chosen').val('').change()
{
alert($(".chosen-select").val());
}