How do I access values created by serializeArray in JQuery?

前端 未结 8 638
眼角桃花
眼角桃花 2021-02-02 09:33

I have this HTML:

And I create an object array from it lik

8条回答
  •  失恋的感觉
    2021-02-02 10:22

    You can either loop through, as @Tom has...or if you're accessing more than one, be a bit more efficient and loop once, creating an object like this:

    var dataArray = $("#myform").serializeArray(),
        len = dataArray.length,
        dataObj = {};
    
    for (i=0; i

    Then you can access it like you want, for example:

    alert(dataObj['title']); //or alert(dataObj.title);
    

    You can test it out here.

提交回复
热议问题