<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
function clickMe() {
//得到input标签对象
var input = document.getElementById("inputId");
console.log(input.id) //在控制台打印出inputId
console.log(input.type) //text
console.log(input.value) //hello
alert(input.value);
}
</script>
</head>
<body>
<input type="text" id="inputId" value="hello" />
<button onclick="clickMe()">点我</button>
</body>
</html>
效果图:
默认值为hello,点击按钮则弹窗和控制台效果如下:
- 如果文本框输入flora,则
同样点击按钮,效果图如下: