【问题标题】:Why is my simpledialog2 not working in my jQuery Mobile snippet?为什么我的 simpledialog2 在我的 jQuery Mobile 代码段中不起作用?
【发布时间】:2012-04-05 17:14:00
【问题描述】:

每次用户单击列表视图无序列表中的链接时,都会出现一个 simpledialog2 框。这是 simpledialog2 文档的链接。这是在 jQuery Mobile 应用程序中支持弹出框的流行方式。 http://dev.jtsage.com/jQM-SimpleDialog/demos2/index.html

但是,我的代码中没有显示任何对话框。为什么?

这个 Fiddle 包含我的代码。 http://jsfiddle.net/ykHTa/2/

这是我的 HTML。

<ul data-role="listview">
    <li><a href="#">foo</a></li>
    <li><a href="#">bar</a></li>
    <li><a href="#">baz</a></li>
</ul>​

这是我的 javascript。

$(function() {

    // When user clicks on a list item, produce a dialogue/alert box.
    $('[data-role="listview"] a').click(function(event) {
        event.preventDefault();
        $('<div>').simpledialog2({
                mode: 'blank',
                headerText: "Popup title",
                headerClose: true,
                blankContent: 
                "My message to you."
        });
    });
});

【问题讨论】:

    标签: javascript jquery jquery-plugins jquery-mobile


    【解决方案1】:

    大卫,您的 javascript 示例在此处缺少右括号:

           });
        }); // - close click binding
    });
    

    更新

    通过将其添加到您的 simpledialog2 方法调用中,我得到了它在您的示例 (jsfiddle) 中的工作:

    dialogForce: true,
    

    基于此处的文档:http://dev.jtsage.com/jQM-SimpleDialog/demos2/dialog.html

    希望这会有所帮助!

    【讨论】:

    • 谢谢,我没有注意到缺少的括号。真的,你认为我需要更多的设置?我想我包含了所有必要的标头 javascript 和 CSS 文件。
    • 啊。实际上,这已经证明了代码中的一个错误 - SD2 假设(在这种情况下不正确)某处存在
      ...
    【解决方案2】:

    尝试用函数调用替换调用?..我遇到了同样的问题,并且 在委托中调用函数似乎可以工作..

    $(function() { 
        // When user clicks on a list item, produce a dialogue/alert box. 
        $('[data-role="listview"] a').click(function(event) { 
            event.preventDefault(); 
            fn();
        }); 
    }); 
    
    function fn() {
        $('<div>').simpledialog2({ 
            mode: 'blank', 
            headerText: "Popup title", 
            headerClose: true, 
            blankContent:  
            "My message to you." 
        }); 
    }
    

    ... simpledialog2 ssem 在 ajax .success 处理程序中更好地工作????

    【讨论】:

      猜你喜欢
      • 2018-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-23
      • 2013-08-06
      • 2021-03-17
      • 2018-04-24
      相关资源
      最近更新 更多