2009-06-19 7 views
1

je veux obtenir l'ID de la barre d'URL et l'insérer dans le hrefURL id Bar = 1 Dans ID jQuery

$ («un [send_message.php 'href =? Act = h & id = $ id '] "). colorbox ({largeur:" 500 ", hauteur:" 350 ", iframe: true});

Répondre

3

il y a un plugin jquery pour faire de ce ridiculement simple:

voir: http://plugins.jquery.com/project/query-object

par exemple

var id = $.query.get('id'); 
$("a[href='send_message.php?act=pm&id="+id+"']").colorbox({width:"500", height:"350", iframe:true}); 
1

Pour ceux qui n'utilisant jQuery ou tout autre bibliothèque JS:

var searchString = document.location.search; 

// strip off the leading '?' 
searchString = searchString.substring(1); 

var gvPairs = searchString.split("&"); 
var getVars = []; 

for (i = 0; i < gvPairs.length; i++) 
{ 
    var gvPair = gvPairs[i].split("="); 
    getVars[gvPair[0]] = gvPair[1]; 
} 

Donc, si la chaîne URL est index.php id = 3 & page = 2 & display = 10 puis:
getVars['id'] = 3;
getVars['page'] = 2;
getVars['display'] = 10;

+1

devrait-il pas: 'var getVars = [] ' – slebetman

+0

Vous avez raison. Je vous remercie – jsnfwlr