进去页面之后 默认选中其中一个单选框 其他的单选框为禁用状态
时间: 2024-04-29 15:26:44 浏览: 7
您的问题是如何实现页面中某一个单选框默认选中,并让其他单选框处于禁用状态?
可以使用JavaScript来实现这个功能。首先,为所有单选框添加相同的类名,然后使用querySelector()函数选中要默认选中的单选框,并使用checked属性将其选中。接着,使用querySelectorAll()函数选中其他单选框,并使用disabled属性将其禁用。
下面是示例代码:
HTML:
```html
<input type="radio" name="options" class="option">Option 1</input>
<input type="radio" name="options" class="option">Option 2</input>
<input type="radio" name="options" class="option">Option 3</input>
```
JavaScript:
```javascript
// 选中要默认选中的单选框
const defaultOption = document.querySelector('.option:nth-of-type(1)');
defaultOption.checked = true;
// 禁用其他单选框
const otherOptions = document.querySelectorAll('.option:not(:nth-of-type(1))');
otherOptions.forEach(option => {
option.disabled = true;
});
```