开发者

how to read table values and send to controller

I have created a table and the values are filled in by the user. The user can create new rows.

How can I get the values of the table开发者_如何学运维 and send it to my controller using jquery or any other method?

Please give me an example.


create a class for your cells like class="AnswerCell" and then get the array from jquery like this:

val myanswers = $.(".AnswerCell");

Then do your post like this:

$.post("myActionMethod", {answers: myanswers});

and the actionmethod should look like this:

public ActionMethod myActionMethod(String[] answers)
{
//do something
}

Hope this helps.


First of all you should give a properly names for your inputs, and than you can whether post a form or make asynchronous get using jQuery.getJSON()


Try this:

$('#mytable tr').each(function() {     
    var fieldValue = $(this).find("td").eq(2).html();     
}); 

This would use jQuery to pull the 3rd row (it starts at 0) and get the value in the first TD there. 'mytable' is the ID of the table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜