2

有没有办法让它,如果我去例如: http://www.example.org/modal.html?openmodal=true模态将打开 onLoad 但如果我去http://www.example .org/modal.html模态不会在加载时打开?

4

1 回答 1

4

http://getbootstrap.com/javascript/#modals告诉你$('#myModal').modal('show')手动打开一个窗口。所以用你的模态得到 id="myModal",试试这个:

//from: https://stackoverflow.com/questions/3788125/jquery-querystring  
function querystring(key) {
   var re=new RegExp('(?:\\?|&)'+key+'=(.*?)(?=&|$)','gi');
   var r=[], m;
   while ((m=re.exec(document.location.search)) != null) r.push(m[1]);
   return r;
}
var querystring = querystring('modal');
if (querystring.length && querystring[0]==='true' ) {$('#myModal').modal('show');}

这将在设置 ?modal=true 时打开模式。

参考:jQuery 查询字符串

于 2013-08-23T12:14:44.277 回答