2012-02-03 69 views
0
$('td.qid').text(). 

上面的代码将确定警报所引用的行。下面是警觉的样子:我在哪里放置此代码,以便它出现在警报中

You have not entered a valid Question 

Please Enter in the Number of Answers you Require for this question 

Please enter in a figure for Number of Marks for this Question 

我想提醒的样子如下:

You have errors on question number: 1 

You have not entered a valid Question 

Please Enter in the Number of Answers you Require for this question 

Please enter in a figure for Number of Marks for this Question 

我的问题是,我在哪里把“你有问题,一些错误”,代码$('td.qid').text()在下面的函数中能够显示警报顶部的'您在问题编号上有错误:1'?

下面是验证功能:

var qnum = 1; 

function insertQuestion(form) { 

    var $tbody = $('#qandatbl > tbody'); 
    var $tr = $("<tr class='optionAndAnswer' align='center'></tr>"); 
    var $qid = $("<td class='qid'>" + qnum + "</td>"); 

$tr.append($qid); 
$tbody.append($tr); 

    $(form).find('.numberOfQuestions').val(qnum); 

    ++qnum; 
    $("#questionNum").text(qnum); 

} 

感谢

回答

0

让我们说你的html页面看起来是这样的:

> <html> <body> 
> <table border="1" width="200"> 
>  <tr> 
>   <td class='qid'>1</td> 
>   <td>bla bla</td> 
>  </tr> 
>  <tr> 
>   <td class='qid'>2</td> 
>   <td>bla bla</td> 
>  </tr> 
>  <tr> 
>   <td class='qid'>3</td> 
>   <td>bla bla</td> 
>  </tr> 
> </table> 
> </body> </html> 

然后添加一个jQuery这样的代码:

$("tr").click(function(e){ 
    var _qid = $("td.qid", this).text(); 
    var _msg = "You have errors on question number:" + _qid ; 
    alert(_msg); 
}); 

通过做t他为每个人添加一个点击事件,然后用qid类挑选该列的文本并构建您的消息。您可以在此尝试:http://jsfiddle.net/franky/f956k/

相关问题