对于Bootstrap中的输入字段,我有以下代码:
<div class="form-group">
<label for="f2">F</label>
<input type="text" class="form-control" name="f2" id="f2">
</div>
我还有一个外部的.js脚本,它需要接收用户输入的信息。如何使用.js脚本访问用户输入?
通过使用选择器。就像这样:const i = document.getElementById('f2');
在此之后,您可以访问输入元素。console.log(i.value)
const inputEl = document.getElementById('f2') // get input from the DOM
const inputValue = inputEl.value