【问题标题】:call jQuery dialog from website url从网站 url 调用 jQuery 对话框
【发布时间】:2012-12-14 08:56:31
【问题描述】:

我正在尝试做这样的事情: https://www.easybring.com/#registration

如您所见,“注册”在 jquery 对话框中,可以通过单击网站内的注册按钮打开。直到现在我都很好:

<a onClick="showDialog({$product['id']});">More Info </a>

我的头包含:

function showDialog(productID){
    $( "#dialog-modal_"+productID ).dialog({
        width: 770,
        height: 590,
        modal: true,
        open: function(event, ui){
        }
    });
}

当然我还有 div:

<div id="dialog-modal_{$product['id']}" style="display: none;">
<iframe src="index.php?act=showProduct&id={$product['id']}" width="100%" height="100%" frameborder="0" scrolling="no"></iframe> 
</div>

但我想做的是通过网站 url 调用该 jquery 特定对话框:#registration。

我该怎么做?

非常感谢!

【问题讨论】:

    标签: javascript jquery html css


    【解决方案1】:

    这个应该可以的:

    $(document).ready(function() {
    if( window.location.href.indexOf( '#registration' ) != -1 ) {
        showDialog({$product['id']});
    }
    });
    

    希望对你有帮助:)

    【讨论】:

    • 现在:有没有一种简单的方法可以将 #registeration 替换为 #product-___ :我认为它会出现在正则表达式中?而不是 cal showDialon( id ) ...
    • 没关系-我通过javascript拆分成功地做到了这一点。非常感谢!
    【解决方案2】:

    你为什么不在 $(document).ready()

    里面调用 showDialog()

    类似的东西

     $(document).ready(function(){
        $("#dialog-modal").dialog({modal: true});
    });
    

    【讨论】:

      【解决方案3】:

      您可以在文档加载事件中处理您的网址:

      $(function() {
          if (window.location.toString().indexOf('#registration') > -1) {
              showDialog({$product['id']});
          }
      });
      

      代码可能行不通,但我认为这个想法很明确。

      这可能有助于您在 JS 中使用 url 字符串:How to get the anchor from the URL using jQuery?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-31
        • 2014-09-11
        • 1970-01-01
        • 2013-01-12
        • 1970-01-01
        相关资源
        最近更新 更多