我试图调用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 : {});
所以我不明白为什么这个不是。
答案 0 :(得分:3)
您正在覆盖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 : {});