选定的内容在变更后不更新

时间:2018-11-25 21:03:49

标签: jquery

我一直在尝试研究其他人关于使用$(“#sub-cats”)。trigger(“ chosen:updated”);的评论。对于我的.change函数和我自己的一生,在脚本为空之后,我无法让我的选择更新并添加了新选项。

原始select每次都会按预期使用新选项进行更新,这似乎是由于selected-select的更新所致。

<script>
                $("#top-category").change(function(){
                  var id = $(this).find("option:selected").attr("id");

                  switch (id){
                    case "career":
$('#sub-cats')
.find('option')
.remove()
.end()
.append('<option value="whatever">text</option>')
.val('whatever')
;


                      break;
                    case "interview":
$('#sub-cats')
.find('option')
.remove()
.end()
.append('<option value="whatever">another text</option>')
.val('whatever')
;                        
                      break;
                    case "all":

                      break;
                  }
                });

            </script>

更新:抱歉,上面我可能还不太清楚,我的第一选择(#top-category)onchange通过清空所有选项并添加新选项来更改#sub-cats的内容。除了selects还合并了jquery selected-select之外,此过程运行完美,原始的select框正确更新,但selected-select不会接受更改。

我尝试添加.trigger(“ chosen:updated”);到每个单独的onchange动作,以及.change语句的末尾,都没有影响。

0 个答案:

没有答案
相关问题