gpt4 book ai didi

javascript - 在 DOM 中显示 radio 属性

转载 作者:行者123 更新时间:2023-11-28 06:56:31 26 4
gpt4 key购买 nike

所以我点击了这个单选按钮,它确实点击了。除了当我检查 DOM 时,我没有看到添加了选中的属性,但我可以看到属性检查已设置为 true。由于我正在保存 HTML,所以我需要能够保留此状态。当属性发生变化时,是否可以添加/删除选中的属性?除了在单击时添加处理程序并检查属性以添加或删除属性之外。

enter image description here

最佳答案

如果您希望 DOM 更改,则必须手动设置。 DOM 不会自动修改自身。

要获取单选按钮的当前值,请使用 javascript:

document.getElementById("radio_group_92").checked // true or false

要设置该值,请使用:

var radiobtn = document.getElementById("the_id_of_the_group");
radiobtn.checked = true;

单选按钮documentation仅指定有关检查的属性:

Definition and Usage

The checked property sets or returns the checked state of a radio button.

This property reflects the HTML checked attribute.

关于javascript - 在 DOM 中显示 radio 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32530133/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com