如何从文本框中获取价值,当我点击按钮时,我的功能适用于文本框值 这个程序用于计算年龄
function getDate(birth){
var now = new Date();
var currentYear = now.getFullYear();
var currentMonth = now.getMonth();
var currentDay = now.getDate();
var birthYear = birth.getFullYear();
var birthMonth = birth.getMonth();
var birthDay = birth.getDate();
var age = currentYear - birthYear;
var age_month = currentMonth - birthmonth;
}
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="javascript.js"></script>
</head>
<body>
<form>
<input type="text"/>
<input type="button" value="Calc" onclick="getAge()"/>
</form>
</body>
</html>
答案 0 :(得分:1)
function getAge(){
var text=document.getElementById('myInput').value;
console.log(text);
}
&#13;
<input id="myInput" type="text"/>
<input type="button" value="Calc" onclick="getAge()"/>
&#13;