【问题标题】:Twitter bootstrap modal URL argumentsTwitter 引导模式 URL 参数
【发布时间】:2013-08-22 23:04:59
【问题描述】:

有没有办法让我去例如: http://www.example.org/modal.html?openmodal=true 模态将打开 onLoad 但如果我转到 http://www.example.org/modal.html 模态将不会打开 onload?

【问题讨论】:

    标签: javascript arguments twitter-bootstrap-3 bootstrap-modal


    【解决方案1】:

    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 querystring

    【讨论】:

    • 我也可以将此代码与其他 url 参数一起用于不同的事情吗?
    • yes 将querystring('modal'); 中的'modal' 替换为您的GET var 的名称并更改if 语句。那么与 ? ?modal2=true 使用var querystring = querystring('modal2'); if (querystring.length && querystring[0]==='true' ) {//code your action here}。或者使用 var querystring = querystring('modal'); if (querystring.length && querystring[0]==='display' ) {//code your action here} 改变 var 的值,例如 ?modal=display
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-05
    • 1970-01-01
    • 2012-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多