开发者

Capturing data with jQuery to use with PHP - non-standard implementation question

I have a unique setup in my program where I have multiple fields, each with non-standard attributes.

For instance (general example):

<textarea id=1 name='text1' level=1 parent=0></textarea>
<textarea id=2 name='text2' level=1 parent=1></textarea>
<textarea id=3 name='text3' level=2 parent=2></textarea>
<textarea id=4 name='text4' level=2 parent=3></textarea>

I want to use jQuery to capture each individual elements and their attributes and send them to my PHP script.

I have yet to be able to figure this one out using a cl开发者_JAVA技巧ean method. Any ideas?


Add a class to each one of them and serialize them using a jQuery class selector?


How about something this:

var attrs = ['name', 'level', 'parent'];
var result = {'name': [], 'level': [], 'parent': []};

for (var i = 0; i < attrs.length; i++) {
    $('textarea').each(function () {
        result[attrs[i]].push($(this).attr(attrs[i]));
    });
}
console.log(result);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜