[英]How to get a value from a Html radio button
I have a html radio button, but I want to know how can I get a value from it. 我有一个html单选按钮,但我想知道如何从中获取值。 (I'm working on Electron)
(我正在研究Electron)
Here is my Radio code 这是我的无线电代码
<label class="container">Ne plus afficher cette page au lancement.<input type="checkbox" unchecked="uncheck"><span class="checkmark"></span>
Basically I want to call a funtion if the box is checked. 基本上,如果该框已选中,我想调用一个函数。
for exemple 举个例子
Function typeFunction(){
//load a window (Not sure if this is right
mainWindow.loadFile('index.html')
}
First, you need to remove that unchecked
tag its useless. 首先,您需要删除
unchecked
标记,使其无效。 Secondly, give a class to the checkbox for example " checkButton ". 其次,给复选框一个类,例如“checkButton”。 Lastly, you need to select the Item from the DOM.
最后,您需要从DOM中选择项目。
const checkBtn = document.querySelector('.checkButton');
If you want to DO something when the checkbox is checked you just need to use the .checked property -> 如果您想在选中复选框时执行某些操作,则只需使用.checked属性->
if(checkBtn.checked) {
// do something
} else {
// do something else
}
Also use function
because if you are gonna use it with capital ,,F'' JS is gonna think this is a function constructor
. 也使用
function
因为如果你要用它来使用它,F''JS会认为这是一个function constructor
。
Give ids to each choice. 给每个选择ID。
id="choice1" ID = “选择1”
Then get the value by referring to the said id. 然后通过参考所述id获得该值。 choice1.value
choice1.value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.