Aras PLM:获取 HTML 控件的值 - JavaScript 指南
要获取窗体上 HTML 控件的值,可以使用 JavaScript 来实现。以下是一种可能的方法:
- 使用
document.getElementById方法获取 HTML 控件的元素对象。例如,如果要获取一个文本框的值,可以使用以下代码:
var textBox = document.getElementById('textBoxId');
- 使用元素对象的
value属性获取控件的值。例如,如果要获取文本框的值,可以使用以下代码:
var textBoxValue = textBox.value;
完整的示例代码如下所示:
<!DOCTYPE html>
<html>
<body>
<form>
<label for="textBoxId">文本框:</label>
<input type="text" id="textBoxId" name="textBoxName" value="默认值"><br><br>
<input type="button" value="获取值" onclick="getValue()">
</form>
<script>
function getValue() {
var textBox = document.getElementById('textBoxId');
var textBoxValue = textBox.value;
console.log(textBoxValue);
}
</script>
</body>
</html>
在上面的代码中,我们使用 document.getElementById 方法获取了 id 为 'textBoxId' 的文本框元素对象,并使用其 value 属性获取了文本框的值。然后,我们在控制台上打印了该值。
原文地址: https://www.cveoy.top/t/topic/pj6Z 著作权归作者所有。请勿转载和采集!