function getquery_build(query,name,value){
query = query + (query.slice(0, 1) == '?' ? '&'+name+'='+value : '?'+name+'='+value);
return encodeURI(query);
}
query = query + (query.slice(0, 1) == '?' ? '&'+name+'='+value : '?'+name+'='+value);
return encodeURI(query);
}
Comment utiliser:
query = "";
query = getquery_build(query, 'index1', 'value1');
query = getquery_build(query, 'index2', 'value2');
query = getquery_build(query, 'index3', 'value3');
query = getquery_build(query, 'index4', 'value4');
console.log(query);
query = getquery_build(query, 'index1', 'value1');
query = getquery_build(query, 'index2', 'value2');
query = getquery_build(query, 'index3', 'value3');
query = getquery_build(query, 'index4', 'value4');
console.log(query);
Le résultat:
?index1=value1&index2=value2&index2=value2&index2=value2
Aucun commentaire:
Enregistrer un commentaire