开发者

thickbox plugin - Identify

开发者 https://www.devze.com 2023-03-22 15:45 出处:网络
I\'m calling the (fairly old) plugin \"thickbox\" as described here: <input type=\"text\" id=\"RecordType\" size=\"10\">

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

精彩评论

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

关注公众号