js根据ID获取输入框的值

HTML

<input id="ti" type="text" placeholder="请输入内容"><button onclick="show()">点击获取输入框的内容</button>

js

function show(){

var b=document.getElementById('ti').value

console.log(b)

}

测试

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>测试</title>

</head>

<body>

<input id="ti" type="text" placeholder="请输入内容"><button onclick="show()">点击获取输入框的内容</button>

<script>

function show(){

var b=document.getElementById('ti').value

console.log(b)

}

</script>

</body>

</html>

猜你喜欢

转载自blog.csdn.net/AIB_Kasic/article/details/90758984
今日推荐