繁体   English   中英

为什么单击时未调用javascript代码

[英]Why javascript code is not being called when I click

我正在尝试调用javascript代码,但是当我在Chrome中的devtools中单击调试时,没有调用javascript,所以我想知道为什么会这样。

这是我的HTML代码:

    <a href="" data-icon="grid" data-rel="popup" data-role="button" data-iconpos="notext" data-inline="true" data-position-to="window" data-transition="pop" data-mini="true" data-theme="c" data-overlay-theme="none"
onclick="ws.su.waypoints.editPopup(this,',id,');">
                        Edit
                    </a>

我有一个js文件,其中有:

(function(ws){
    ws.su = {
waypoints: {
            editPopup: function (elem, id) {
                var popup = $.mobile.activePage.find('#su-waypoint-edit');
                var schmElem = popup.find('[data-schema]');
                var tmp = $($A.getArchetypeTemplate(schmElem));
                tmp.attr('data-item', id);
                $A.archetypeSectionRefreshData(schmElem);
                popup.popup('open');
            }
        }

}

    })(ws != undefined ? ws : {});

有什么想法我想念的吗?

这是起作用的代码:

<a href="" data-icon="grid" data-rel="popup" data-role="button" data-iconpos="notext" data-inline="true" data-position-to="window" data-transition="pop" data-mini="true" data-theme="c" data-overlay-theme="none"
                           onclick="ws.su.users.editPopup(this,',id,');">
                            Edit
                        </a>

JavaScript代码:

(function(ws){
    ws.su = {
         users: {
            editPopup: function(elem, id){
                var popup = $.mobile.activePage.find('#su-popup-edit-user');
                var schmElem = popup.find('[data-schema]');
                var tmp = $($A.getArchetypeTemplate(schmElem));
                tmp.attr('data-item', id);
                $A.archetypeSectionRefreshData(schmElem);
                popup.popup('open');
            }
    }
})(ws != undefined ? ws : {});

所以我不明白为什么这个不是。

您正在覆盖ws.su ,而不是将其与新属性合并。 采用:

(function(ws){
    ws.su = ws.su || {};
    ws.su.waypoints = ws.su.waypoints || {};
    ws.su.waypoints.editPopup = function (elem, id) {
        var popup = $.mobile.activePage.find('#su-waypoint-edit');
        var schmElem = popup.find('[data-motocol-schema]');
        var tmp = $($A.getArchetypeTemplate(schmElem));
        tmp.attr('data-motocol-item', id);
        $A.archetypeSectionRefreshData(schmElem);
        popup.popup('open');
    }
})(ws != undefined ? ws : {});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM