【发布时间】:2011-11-28 02:19:47
【问题描述】:
这是我想知道的。我有一个表,其行数取决于微调器中的数字。这确实有效,例如如果我在微调器中输入 25,它会出现 25 行,如果我在微调器中输入 7,则会出现 7 行。
所以我的问题是这样的:
假设一个表中有许多行。我所拥有的是一个文本区域,用户输入他们的问题然后提交问题,问题应该被插入并出现在“问题”列下表格的第一行,文本区域变为空白,用户输入他的第二个问题,如果用户提交此问题,则该问题将出现在第二行,第三个问题出现在第三行,第四个问题出现在第四行等。
问题是我不知道该怎么做。有人可以告诉我如何实现这一目标。我不是一个强大的 Javascript 程序员,我更像是一个 Oracle 和 MYSQL 程序员,但我需要在我的项目中使用 Javascript。
任何帮助将不胜感激
以下是我的 Javascript 代码:
<script type="text/javascript">
function insertQuestion() {
var qandatable = document.getElementById("qandatbl");
var questionDiv = document.getElementById("question");
var getQuestion = document.getElementById("questionTextarea");
var rowCount = qandatable.rows.length;
var row = qandatable.insertRow(rowCount);
var questionCell = row.insertCell(getQuestion);
questionCell.innerHTML = getQuestion.value;
}
</script>
下面是html代码:
//table where questions would be stored
<table id="qandatbl" align="center">
<thead>
<tr>
<th><span id="qidhead">Question No</span></th>
<th><span id="questionhead">Question</span></th>
</tr>
</thead>
<tbody>
<?php
$spinnerCount = $_POST['textQuestion'];
if($spinnerCount > 0) {
for($i = 1; $i <= $spinnerCount; $i++) {?>
<tr>
<td id="qid"><?php echo $i; ?></td>
<td id="question"></td>
</tr>
</tbody>
<?php
}
}
?>
</table>
//table which consists of textarea and submit button
<form id="enter" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<table id='middleDetails' border='1'>
<tr>
<th class='tblheading' colspan='2'>SESSION DETAILS</th>
</tr>
<tr>
<td id="questionNum">Question No </td>
</tr>
<tr>
<td id="questionContent">Question:</td>
<td id="questionTextarea"><textarea rows="5" cols="40" id="questionTxt" name="questionText"></textarea></td>
</tr>
<tr>
<td id="addQuestionRow" colspan='2'><input id="addQuestion" type="button" value="Add Question" name="addQuestionBtn" onClick="insertQuestion()" /></td>
</tr>
</table>
</form>
【问题讨论】:
标签: javascript button insert html-table textarea