我有1个输入字段(name =" no_of_days")和1个标签(name =" label_days")和提交按钮。输入天数时点击 提交按钮我想显示标签数量。 例如:= no_of_days == 5然后 显示5个标签 我想使用javascript和html以及nodejs
这是我的尝试.. 但是console.log("内部功能");不会来cmd。 (我的英语不好。我猜你能理解我说的话)
//package1.handlebars
<form action="/users/package1" method="post">
<div id="container">
<input name="test" type="text" >
<input value="add" type="submit" onClick="add()">
</div>
//end package1.handlebars
//inside routes file > users.js
router.get('/package1', function(req, res) {
res.render('package1');
});
router.post('/package1', function(req, res) {
res.render('package1');
var i=0;
console.log(i);
function add(){
console.log("inside function");
if (User.getElementById('test').value!='')
{
i++;
var title =User.getElementById('test').value;
var node = User.createElement('div');
node.innerHTML = '<input type="checkbox" id="check' + i + '" name="check' + i + '"><label for="check' + i + '">'+ test +'</label>';
User.getElementById('container').appendChild(node);
}
};
});
答案 0 :(得分:2)
<!DOCTYPE html>
<html>
<body>
<label> no_of_days </label>
<input type="number" id="myNumber" value="2" name="no_of_days">
<button type="button" onclick="myFunction()"> Submit </button>
<p id="demo"></p>
<script>
function myFunction() {
var label = "";
var x = document.getElementById("myNumber").value;
for(var i =1; i <= x; i++){
label += "label day:" +i + "<br>";
}
document.getElementById("demo").innerHTML = label;
}
</script>
</body>
</html>