[英]how to remove attribute selected from all selected options in select in jquery
我不會刪除從 jquery 中所有選定選項中選擇的屬性。
請幫我。
我的 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>
以及所有最重要的方法都不起作用。
選定的選項長度僅返回 1。我不做 select 所有選定的選項以刪除選定的屬性。
坦克的一切。
只需將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.