您好,我的页面上有两个评级字段,当选中第一个评级并选中第二个时,第一个未选中。这在后端不是问题,因为评分的值已经保存,但对于访问者来说这是个问题,因为星星消失了。
在 javascript 或 jQuery 中有没有一种方法可以说:如果这个字段被选中,它仍然是被选中的?
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<fieldset class="rate">
<input id="5-stars-1" type="radio" name="firstRate" value="5" />
<label for="5-stars-1">5</label>
<input id="4-stars-1" type="radio" name="firstRate" value="4" />
<label for="4-stars-1">5</label>
</fieldset>
<fieldset class="rate2">
<input id="5-stars-2" type="radio" name="secondRate" value="5" />
<label for="5-stars-2">5</label>
<input id="4-stars-2" type="radio" name="secondRate" value="4" />
<label for="4-stars-2">5</label>
</fieldset>
你有什么想法吗?
如果您需要更多信息或从我的代码中提取更多信息,请不要介意询问!
最佳答案
好吧,感谢 Rory 和 Sathish,答案非常简单:
radio 被设计为一次检查一次,所以我不能做我想做的事,相反,我只需要切换到复选框,问题就解决了!
再次感谢!
关于javascript - 检查另一个单选按钮字段时如何强制单选按钮保持选中状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56223450/