基于选择的单选按钮条件

radio button condition based on selection

本文关键字:单选按钮 条件 选择 于选择      更新时间:2023-09-26

我有一个带有id="pay"的单选按钮和一个函数,如果选择单选按钮,我需要执行该函数。任何帮助吗?

function getMn() {
    var int = document.getElementById("pay").value;
    return int;
}
<input type="radio" id="pay" value="pass" onClick="getMn(this.value)"/>

或者如果你不想把值传递给函数,只执行函数,那么你可以简单地调用function

<input type="radio" id="pay" value="pass" onClick="getMn()"/>

为单选按钮添加一个click事件,并检查它是否被选中…

document.getElementById('pay').onclick = function(){ 
    if(document.getElementById('pay').checked) {
      //call your function here
    }
};