Javascript 如何在选择新评级值时删除以前选择的选项

Javascript 如何在选择新评级值时删除以前选择的选项,javascript,jquery,rating,Javascript,Jquery,Rating,我正在使用jquerybar评级 当用户选择新的评级值时,我想删除以前选择的选项。 以下是脚本: <script> $(function () { $('.rating').barrating('show',{ theme: 'fontawesome-stars', initialRating: '0', onSelect: function (value, text, event) {

我正在使用jquerybar评级

当用户选择新的评级值时,我想删除以前选择的选项。 以下是脚本:

<script>
    $(function () {
        $('.rating').barrating('show',{
            theme: 'fontawesome-stars',
            initialRating: '0',
            onSelect: function (value, text, event) {
                if (typeof (event) !== 'undefined') {
                  $('#avis_nombre option:selected').removeAttr('selected');
                  document.querySelector('#avis_nombre option[value="' + value + '"]').setAttribute('selected', 'selected');
                }
            },
        });
    });
</script>
每次用户选择新的额定值时,这将显示选择选项的输出方式


您的代码可以完美地工作:

$function{ $‘示例’。连珠炮式的‘表演’{ 主题:"超级明星",, 初始评级:“0”, onSelect:函数值、文本、事件{ 如果typeofevent!=“未定义”{ $'avis_nombre option:selected'。删除'selected'; document.querySelector'avis_nombre option[value='+value+']'。setAttribute'selected','selected'; } }, }; }; 1. 2. 3. 4. 5. 1. 2. 3. 4. 5.
谢谢,在测试发送表单而不添加“选择到”选项后,它工作正常,数据保存在数据库中@豪斯凯尔凯尔