从 jQuery 序列化生成的字符串中获取变量


如何

从jQuery的.serialize()方法生成的字符串中获取变量的值?是否有本机函数来执行此操作?

例如

item1=foobar&item2=somethingelse

其中item1是感兴趣的变量。

没有原生方法,但您可以从这里获取unserialize函数: https://gist.github.com/rcmachado/242617

并运行:$.unserialize('item1=foobar&item2=somethingelse')

返回一个数组。您甚至可以这样做:

$.unserialize('item1=foobar&item2=somethingelse')['item1'];

返回"福巴">

最新更新