开发者

thickbox plugin - Identify

I'm calling the (fairly old) plugin "thickbox" as described here:

<input type="text" id="RecordType" size="10">
<a id="RecSubTypeHref" href="index.pl?img=true&type=RecSubType" class="thickbox" disabled title='Title goes here'><img border=0 src='images/questionmark.png'></a>

When the thickbox is created it contains a list of stuff based on the query.

开发者_StackOverflowUsing JavaScript or jQuery I'd like to be able to access the value of type (in the example above type=RecSubType).


// Adapted from http://tinyurl.com/pqxtu2
function getQuerystring(url, key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(url);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

var href = $('a#RecSubTypeHref')[0].href;
console.log(getQuerystring(href, 'type'));

Live demo.

Too easy ;)


(Also see How can I get query string values in JavaScript? for more handy query string parsing approaches.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜