我有一个循环来回答看起来像这样的问题:
<?php
while ($u=mysql_fetch_array($result)){
?>
<table>
<tr>
<td>Question_ID</td>
<td>Question</td>
<td>Answer</td>
</tr>
<tr>
<td><? echo $u['question_id'];?></td>
<td><? echo $u['question'];?></td>
<td>
<form>
<input type="hidden" value="echo $u['question_id'];?>" />
<input type="text"/>
<a href="#" onClick="ajax_answer();">Send Answer</a>
</form>
</td>
</tr>
</table>
<?php
}
?>
例如,如果用户回答页面上出现的第三个问题,我的问题是如何捕获写入的文本和 question_id,以便将这些变量发送到 php 页面?
<script>
function ajax_answer(){
$.ajax({
question_id = ??? //how do I capture this variable?
answer = ??? //how do I capture this variable?
url:'answers.php',
type:'POST',
dataType:'text/html',
data:'question_id='+question_id + '&answer='+answer,
success: function(){
};
});
};
</script>
谢谢!