jquery - explode, match and get value -
this question has answer here:
- how can query string values in javascript? 73 answers
i have string:
title=hello world&dropdown=on&count=on&hierarchical=on
and want explode string &
, like;
title=hello world dropdown=on count=on hierarchical=on
i know names title, dropdown, count,hierarchical (but names not fixed, can anything),
now want match names (name means words before equal sign) name know, if match value (words after equal sign), like:
if (name == myname) value
var myname = dropdown; if (dropdown == myname)alert(dropdown.value)
split string array, put array object, can compare nicely:
var string = "title=hello world&dropdown=on&count=on&hierarchical=on"; var stringarr = string.split("&"); console.log(stringarr); var newobj = {}; (var = 0; < stringarr.length; i++) { var parts = stringarr[i].split("="); newobj[parts[0]] = parts[1]; } console.log(newobj);
now, newobj.title
equal hello world
. hope helps.
oh, , fiddle: http://jsfiddle.net/kxmlp/
Comments
Post a Comment