jQuery 选择,以更新<选项>字段
jquery chosen, to update <option> fields
有 HTML:
<form id='country'>
<select id="region" name="region" class='chosen'>
<?=$regions;?>
</select>
<br>
<select id="city" name="city" class='chosen'></select>
<br>
<select id="district" name="district" class='chosen'></select>
<br>
<select id="village" name="village" class='chosen'></select>
</form>
我的选项获取 Ajax 的内容:
$(document).ready(function(){
$("#region").on("change", function(){
$(this).nextAll('select').html('');
$.ajax({
type: "POST",
url: "index.php",
data: "ter_id="+$(this).val(),
success:function(_ajax){
$("#city").html(_ajax);
}
});
$(this).trigger('chosen:updated'); //don't working, as like $("#country").trigger("liszt:updated")
})
我做错了什么?获取 ajax 数据后,我的选项不会更新。我需要写什么以及在哪里写?chosen_v1.2.0.
我不知道
选择是如何工作的,但它需要在成功回调中触发。在您的代码中,您在 ajax 响应可用之前就这样做了。
$(document).ready(function(){
$("#region").on("change", function(){
var that = $(this);
that.nextAll('select').html('');
$.ajax({
type: "POST",
url: "index.php",
data: "ter_id="+that.val(),
success:function(_ajax){
$("#city").html(_ajax);
that.trigger('chosen:updated'); <<=== HERE
}
});
});
});
我知道了。我只是在部分填充后成功应用 selectsen() 方法。
$("#region").on("change", function(){
var that = this;
$(this).nextAll('select').html('').addClass('hidden');
$.ajax({
type: "POST",
url: "index.php",
data: "ter_id="+$(this).val(),
success:function(_ajax){
$("#city").removeClass('hidden').attr('required','required').html(_ajax).chosen({'no_results_text': "Oops, nothing found!"});
}
});
})
相关文章:
- 将选项值附加到隐藏字段
- 我可以在Dynamics CRM 2016的复合地址字段中添加两个选项字段吗
- 如何在angular bootstrap ui中聚焦活动导航选项卡中的拳头输入字段
- 在两个多选字段之间移动选项
- 选项卡式内容中的相同字段
- 仅当选择了特定选项时才显示输入字段
- 构建HTML选择字段并使用JavaScript数组选择选项
- 添加带有选择选项字段的表单
- 添加到前端问题中的购物车和产品选项字段 - Magento
- 禁用对单个非映射选项字段的验证检查
- jQuery - 添加第二个变量以选择选项字段
- 如何在表单.js中插入选择多个选项字段
- 是否可以使用新选项()将ondblclick添加到选项字段
- jQuery 选择,以更新<选项>字段
- 从数据库中选择父选项字段时填充子选项字段的简单方法)
- 如何选择某个选项字段
- 命名html选项字段和复选框,以便在jquery中正确使用它
- 使用jQuery处理更改sharepoint中的多选选项字段
- 如何在选项字段中显示编辑表单和选定值
- 如何在jquery/PHP中通过post传递选项字段和输入框的值