每次按下按钮时添加一个新的文本字段 [英] add a new text field every time a button is pressed
本文介绍了每次按下按钮时添加一个新的文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一些javascript,每次按下按钮时都会创建一个新的文本字段,任何帮助都将被赞赏,它似乎是javascript不想多次运行
<!DOCTYPE html>
< html>
< head>
< title> Q& A管理员面板< / title>
< / head>
< body>
< h1> Q& A管理员面板< / h1>
< form action =add_question.phpmethod =post>
问题类型:< input type =textid =questionType/>
问题名称:< input type =textid =questionName/>
问题文字:< input type =textid =questionText/>
< select id =myListonchange =selectType()>
< option>是或否< / option>
< option>多选< / option>
< option>多选< / option>
< option>打开回应< / option>
< / select>
< div id ='按钮'> < / DIV>
< / form>
< script type =text / javascript>
函数selectType()
{
var type = document.getElementById(myList);
if(type ==Multiple Choiceor type ==Multiple Select){
// add answer = visible
}
}
脚本>
< script type =text / javascript>
var answers = 0;
function addAnswer()
{
write = document.getElementById('buttons');
write.innerHTML = write.innerHMTL +add answer:< input type = \text \id = \answer+ answers +\< br>;
答案=答案+ 1;
}
< / script>
< button onclick =addAnswer(); return false;> add answer< / button>
< / body>
< / html>
解决方案
var答案= 0,
write = document.getElementById('buttons');
function addAnswer(){
write.innerHTML + ='添加答案:< input type =textid =answer'+ answers +'/> < br />';
答案++;
}
i am trying to create a bit of javascript that will create a new text field every time a button is pressed, any help would be appreciated, it seems like the javascript doesn't want to run more than once
<!DOCTYPE html>
<html>
<head>
<title>Q&A Admin Panel</title>
</head>
<body>
<h1>Q&A Admin Panel</h1>
<form action="add_question.php" method="post">
Question Type: <input type="text" id="questionType" />
Question Name: <input type="text" id="questionName" />
Question Text: <input type="text" id="questionText" />
<select id="myList" onchange="selectType()">
<option>Yes or No</option>
<option>Multiple Choice</option>
<option>Multiple Select</option>
<option>Open Response</option>
</select>
<div id='buttons'> </div>
</form>
<script type="text/javascript">
function selectType()
{
var type=document.getElementById("myList");
if(type == "Multiple Choice" or type == "Multiple Select"){
// add answer = visible
}
}
</script>
<script type="text/javascript">
var answers = 0;
function addAnswer()
{
write = document.getElementById('buttons');
write.innerHTML = write.innerHMTL + "add answer: <input type=\"text\" id=\"answer" + answers + "\" <br>";
answers = answers + 1;
}
</script>
<button onclick="addAnswer(); return false;">add answer</button>
</body>
</html>
解决方案
var answers = 0,
write = document.getElementById('buttons');
function addAnswer() {
write.innerHTML += 'Add answer: <input type="text" id="answer"' + answers + '/> <br />';
answers++;
}
这篇关于每次按下按钮时添加一个新的文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文