[英]How do you use an if statement to extract a value from a select tag? (Javascript)
[英]How do you select an input tag and use it in an if statement?
我正在尝试使用一行来使用 input 标签,我正在尝试选择 input 标签的 id 并在 if 语句的参数中使用它,但我似乎无法做到这一点。 选择不需要通过 id。
这是输入标签:
<label for="budget">Cake Budget</label>
<input id="budget" type="number" >
<br><br>
如果您尝试将输入标签作为变量获取:
var tag = document.getElementById("budget");
如果需要,您可以从哪里接收标签中的文本( tag.value
)。
html:
<input id="budget" type="number" onchange="update()">
JS:
function update(){
var e = $('#budget').value
if(e > 100){
/*Your Code Here*/
// 'e' is the name of the variable that has the 'budget' value in it.
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.