我想使用 Javascript 而不是 Jquery 通过标签类获取输入值。我的html代码是:
<label class="btn btn-secondary button-calculator">
<input type="radio" name="units[]" id="units1" value="1" autocomplete="off"> US units
</label>
<label class="btn btn-secondary button-calculator active">
<input type="radio" name="units[]" id="units2" value="2" autocomplete="off" checked=""> Metric units
</label>
Run Code Online (Sandbox Code Playgroud)
我尝试过
document.getElementsByClassName("active").children
Run Code Online (Sandbox Code Playgroud)
和
document.getElementsByClassName("active").value
Run Code Online (Sandbox Code Playgroud)
并检查 console.log 值,但我没有得到任何有用的信息。
提前致谢。