How to implement something like PHP's http_build_query and the reverse in javascript?

后端 未结 3 1027
离开以前
离开以前 2021-02-15 11:24
\'bar\',
              \'baz\'=>\'boom\',
              \'cow\'=>\'milk\',
              \'php\'=>\'hypertext processor\');

         


        
3条回答
  •  佛祖请我去吃肉
    2021-02-15 12:01

    Try the jQuery query plugin. It's pretty intuitive. You can use get and set accessors to read and modify the query string:

    var cow = $.query.get('cow');
    $.query.set('cow', 'goat');
    

    You can create a new query object from an existing string:

    var fromVar = $.query.load('?cow=milk')
    var cow = fromVar.get('cow'); // milk
    

    You can also create an empty object:

    var newQ = $.query.empty();
    newQ = newQ.set('first', 'value'); // "?first=value"
    

提交回复
热议问题