从URL读取数据标记并输入JS变量

时间:2016-05-12 23:15:05

标签: javascript html forms variables uri

一般的想法是有一个URL,index.html?variable01 = response01& variable02 = response02

这将产生js varibles,其中等号前面的字符串作为变量名,而后面的字符串就是它的值。到目前为止我已经尝试了这个:它没有用

var strings = window.location.search("?*") //filter the website URL itself

var varsets = strings.split('&') //split earch variable set, makes var=value

var varcommands = strings.search.append('var ') //add the string 'var to each of the sets, 
makes var var=value

for (x = 0, y < vars.length, x++) { 
 sections = vars.search.replace('=',' = ') //add spaces around the equals sign,
makes var var = value

function x() {  //define a function to process the value of sections as a command
  return sections
 }
 for (y = 0, y < sections.length, y++) { //cycle through and run each command string
  x()
}

0 个答案:

没有答案