Javascript 如何在单击';单击以回答';按钮

Javascript 如何在单击';单击以回答';按钮,javascript,jquery,html-table,Javascript,Jquery,Html Table,我不熟悉javascript、jquery等。我需要帮助,以了解如何在单击按钮后弹出字段,在该字段中输入特定问题的答案,然后在该问题下显示(在同一行)。你也可以在这里查一下 //html <table class='table'><th>Id</th><th>Question</th><th>Date</th><th>Answer</th> <tr> <td> 1

我不熟悉javascript、jquery等。我需要帮助,以了解如何在单击按钮后弹出字段,在该字段中输入特定问题的答案,然后在该问题下显示(在同一行)。你也可以在这里查一下

//html

<table class='table'><th>Id</th><th>Question</th><th>Date</th><th>Answer</th>

<tr>
<td>
1
</td>
 <td>
 Some question here1
</td>
<td> 
Date
</td>
<td>
<button onclick='myFunction()'>Click to answer</button>
</td> 
</tr>
<tr>
<td>
2
</td>
<td>
 Some question here2
</td>
<td> 
Date
</td>
<td>
<button onclick='myFunction()'>Click to answer</button>
</td> 
</tr>
<tr>
<td>
3
</td>
<td>
 Some question here3
</td>
<td> 
Date
</td>
<td>
<button onclick='myFunction()'>Click to answer</button>
</td> 
</tr>
</table>
IdQuestionDateAnswer
1.
这里有些问题1
日期
点击回答
2.
这里有些问题
日期
点击回答
3.
这里有些问题
日期
点击回答

如果您使用的是纯javascript,那么可以使用一些函数参数来执行您想要的操作

大概是这样的:

HTML

点击点击按钮后,我需要弹出一个字段,在那里我可以回答特定的问题?如何在每个问题下的同一行生成答案 问题日期答案 1. 这里有些问题1 日期 点击回答 2. 这里有些问题 日期 点击回答 3. 这里有些问题 日期 点击回答 Javascript:

<script type="text/javascript">
function clickMe(Question, id)
{
var QuestionPrompt = prompt(Question,"Type your answer here...");

if (QuestionPrompt!==null)
  {
      var curText = document.getElementById(id).innerHTML;
      var newText = curText + "<br/>" + QuestionPrompt;
      document.getElementById(id).innerHTML = newText;
  }
}
</script>

功能clickMe(问题,id)
{
var QuestionPrompt=prompt(问题“在此处键入答案…”);
if(QuestionPrompt!==null)
{
var curText=document.getElementById(id).innerHTML;
var newText=curText+“
”+问题提示; document.getElementById(id).innerHTML=newText; } }
onclick事件将发送问题文本和要输入答案的单元格id。javascript函数显示一个简单的输入框,获取答案并将其附加到带有问题的单元格中


不漂亮也不复杂,但它完成了任务。你可以用很多不同的方法来改进它。

你尝试过什么吗?是的,我很少尝试。我在W3上找到了一些东西,但不是我想要的。谢谢。但是,在添加一些文本后,按“确定”后,文本(答案)将不起作用,我的意思是它与问题不在同一单元格(td)中。这个示例对我来说很好。试试浏览器中的DeBugger,看看发生了什么。您可以通过按f12键访问它,如果您使用的是Chrome或Firefox,它将为您标记JS错误。该表位于某个php文件中,所有内容都是ECHO-ed,我希望这不是问题。无论如何谢谢你!您是否向php文件中添加了id?如果不行,那就不行了。如果这不是问题的话,我必须查看php文件以获得帮助。是的,我在php文件中添加了id,但使用了单引号,因为双引号不起作用。我需要再问一个问题,还是直接把php文件发送到这里。(我是新来的……)
<h3 align="center">After hiting the Click button, i need to pop out field where i can answer specific question? How to produce an answer in the same row under each question </h3>
<table class='table'><th>Id</th><th>Question</th><th>Date</th><th>Answer</th>

<tr>
<td>1</td>
 <td id='q1'>Some question here1</td>
<td>Date</td>
 <td><button onclick="clickMe('First Question', 'q1');" type="button">Click to answer</button></td> 
</tr>
<tr>
<td>2</td>
<td id="q2">Some question here2</td>
<td>Date</td>
 <td><button onclick="clickMe('Second Question', 'q2');" type="button">Click to answer</button></td> 
</tr>
<tr>
<td>3</td>
<td id="q3">Some question here3</td>
<td>Date</td>
 <td><button onclick="clickMe('Third Question', 'q3');" type="button">Click to answer</button></td> 
</tr>
</table>
<script type="text/javascript">
function clickMe(Question, id)
{
var QuestionPrompt = prompt(Question,"Type your answer here...");

if (QuestionPrompt!==null)
  {
      var curText = document.getElementById(id).innerHTML;
      var newText = curText + "<br/>" + QuestionPrompt;
      document.getElementById(id).innerHTML = newText;
  }
}
</script>