2012-05-10 4 views

ответ

0
var test = "http://www.example.org/search?q=whatever&another=moretext"; 
var another = test.split('another='); 

другой представляет собой массив с другим [0] = 'http://www.example.org/search?q=whatever &', а другой [1] = 'moretext'.

+0

что, если 'whatever' содержит 'another =' – Sethunath

0

сохранить эту функцию в вашей сумке:

function querySt(qsName, url) 
     { 
      var theUrl; 
      if (url == null || url == undefined) 
       theUrl = window.location.search.substring(1); else theUrl = url; 
      var g = theUrl.split("&"); 
      for (var i = 0; i < g.length; i++) { 
       var pair = g[i].split("="); 
       if (pair[0].toLowerCase() == qsName.toLowerCase()) 
       { 
        return pair[1]; 
       } 
      } 
      return null; 
     } 

использований

alert(querySt("another")+'  '+querySt("q")); 
Смежные вопросы