简体   繁体   English

如何删除从 jquery 中的 select 中的所有选定选项中选择的属性

[英]how to remove attribute selected from all selected options in select in jquery

I'm not remove attribute selected from all selected options in jquery.我不会删除从 jquery 中所有选定选项中选择的属性。

Please help me.请帮我。

My html code is:我的 html 代码是:

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"> $('#commentform.comment-form-rating input#dap_rating').change(function () { $('#commentform.comment-form-rating #rating option').on('change',function() { alert("nb = "+$(this).find(":selected").length); }); $("#commentform.comment-form-rating #rating option:selected").removeAttr("selected"); $("#commentform.comment-form-rating #rating option:selected").prop("selected", false); $("#commentform.comment-form-rating #rating > option:selected").each(function() { }); $(document.body).on('change', '#commentform.comment-form-rating #rating', function () { var c = $('#commentform.comment-form-rating #rating').filter((i, s) => $(s)[0].selectedIndex > 0).length; console.log(c); }); $('#mySelect option:selected').removeAttr('selected'); }); </script> <select name="rating" id="rating" required="" style="display: none;"> <option value="0" selected="selected">رای دهید</option> <option value="5" selected="selected">عالی</option> <option value="4" selected="selected">خوب</option> <option value="3">متوسط</option> <option value="2" selected="selected">نه خیلی بد</option> <option value="1">خیلی بد</option> </select>

and all the top ways not working.以及所有最重要的方法都不起作用。

selected options length return only 1. i'm not to do select all selected options to remove attribute selected.选定的选项长度仅返回 1。我不做 select 所有选定的选项以删除选定的属性。

tank's all.坦克的一切。

Just use removeAttr() for all options:只需将removeAttr()用于所有选项:

 $('#rating option').removeAttr('selected'); console.log($('#rating').html());
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select name="rating" id="rating" required=""> <option value="0" selected="selected">رای دهید</option> <option value="5" selected="selected">عالی</option> <option value="4" selected="selected">خوب</option> <option value="3">متوسط</option> <option value="2" selected="selected">نه خیلی بد</option> <option value="1">خیلی بد</option> </select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM