gpt4 book ai didi

javascript - 如何访问javascript文件中的函数?

转载 作者:太空宇宙 更新时间:2023-11-04 13:26:37 25 4
gpt4 key购买 nike

我正在尝试访问 js 文件中的函数,点击按钮如何访问它?

这是我的htmljs文件的代码。

HTML:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Picker</title>
<link rel="stylesheet" href="resources\css\sencha-touch-debug.css" type="text/css">
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="scripts\ext-touch.js"></script>
<script type="text/javascript" src="scripts\Stocking.js"></script>
<script type="text/javascript" src="scripts\Stockslot.js"></script>
<script type="text/javascript" src="scripts\Datafile.js"></script>
<script type="text/javascript" src="scripts\index.js"></script>
</head>

<body style="margin:0px; padding:0px;">
<script>
function xyz() {
alert("1");
Stocking.onShakeTap();
alert("2");
}
</script>
<button onClick="xyz();">
<table height="1000px" width="2000px" bgcolor="#000000" cellpadding="0px" cellspacing="0px">
<tr>
<td>
</td>
</tr>
</table>
</button>
</body>

</html>

Stocking.js:

var addres,
yem,
bro,
pro = 0;

Ext.Stocker = Ext.extend(Ext.Sheet, {
cmpCls: 'x-picker',
centered: false,
floating: true,
modal: false,
hideOnMaskTap: false,
draggable: false,
monitorOrientation: true,
hidden: true,
arrive: 'center',
depart: 'bottom',
arrivalEffect: 'pop',
departEffect: 'slide',
height: window.innerHeight / 2,
width: window.innerWidth,
stretchX: true,
stretchY: false,
hideOnMaskTap: false,
showDoneButton: false,
useTitles: false,
defaultType: 'stockslot',
initComponent: function() {
this.layout = {
type: 'hbox',
align: 'stretch',
pack: 'start'
};

if (this.slots) {
this.items = this.items ? (Ext.isArray(this.items) ? this.items : [this.items]) : [];
this.items = this.items.concat(this.slots);

}
if (this.useTitles) {
this.defaults = Ext.applyIf(this.defaults || {}, {
title: ''
});
}
this.on('slotpick', this.onSlotPick, this);
this.addEvents('pick', 'change');

Ext.Stocker.superclass.initComponent.call(this);

},

onSlotPick: function(slot, value, node) {
this.fireEvent('pick', this, this.getValue(), slot);
return false;
},

onShakeTap: function() {
alert();
var rand = 0;
addres = 0;
rand = Math.round(Math.random(4) * 5);
this.fireEvent('pick', this, this.getValue(rand));
},

setValue: function(values, animated) {
var key, slot,
items = this.items.items,
ln = items.length;

if (!values) {
for (i = 0; i < ln; i++) {
items[i].setValue(0);
}
return this;
}

for (key in values) {
slot = this.child('[name=' + key + ']');
if (slot) {
slot.setValue(values[key], animated);
}
}

return this;
},

orient: function(orientation, w, h) {
if (!this.container || this.centered || !this.floating) {
return this;
}

var me = this,
cfg = me.initialConfig || {},
size = {
width: cfg.width,
height: cfg.height
},
pos = {
x: cfg.x,
y: cfg.y
},
box = me.el.getPageBox(),
pageBox, scrollTop = 0;


if (me.container.dom == document.body) {
pageBox = {

width: window.innerWidth,
height: window.innerHeight
};

scrollTop = document.body.scrollTop;
} else {
pageBox = me.container.getPageBox();
}

pageBox.centerY = pageBox.height / 2;
pageBox.centerX = pageBox.width / 2;


if (pos.x != undefined || pos.y != undefined) {
pos.x = pos.x || 0;
pos.y = pos.y || 0;

} else {

if (/^(bottom|top)/i.test(me.arrive)) {
size.width = me.stretchX ? pageBox.width : Math.min(200, Math.max(size.width || box.width || pageBox.width, pageBox.width));
size.height = Math.min(size.height || 0, pageBox.height) || undefined;
size = me.setSize(size).getSize();
pos.x = pageBox.centerX - size.width / 2;
pos.y = me.arrive == 'top' ? 0 : pageBox.height - size.height + scrollTop;

} else if (/^(left|right)/i.test(me.arrive)) {

size.height = me.stretchY ? pageBox.height : Math.min(200, Math.max(size.height || box.height || pageBox.height, pageBox.height));
size.width = Math.min(size.width || 0, pageBox.width) || undefined;
size = me.setSize(size).getSize();
pos.y = 0;
pos.x = me.arrive == 'left' ? 0 : pageBox.width - size.width;

} else {
size.height = pageBox.height / 2;
size.width = pageBox.width;
size = me.setSize(size).getSize();
}
}
me.setPosition(pos);
return this;
},

getValue: function(loc) {
var value = {},
items = this.items.items,
ln = items.length,
itemtest, i;

for (i = 0; i < ln; i++) {
itemtest = items[i];
value[itemtest.name] = itemtest.getValue(loc);
}
return value;
}
});

Ext.regModel('x-textvalue', {
fields: ['text', 'value']
});


我想从索引页面访问 stocking.js 文件中的 onShakeTap() 函数。


这里是一些额外的数据:

我实际上是将 Ext.stocker 扩展到 Ext.stockpicker,这里是代码:

Ext.StockPicker = Ext.extend(Ext.Stocker, {
slotOrder: ['valuess', 'pointss', 'stockss'],
initComponent: function() {
this.slots = [];
Ext.each(this.slotOrder, function(item) {
this.slots.push(this.createSlot(item, values, stocks, points));
}, this);
Ext.StockPicker.superclass.initComponent.call(this);
},
stretchX: true,
createSlot: function(name, values, stocks, points) {
switch (name) {
case 'pointss':
return {
name: 'Points',
align: 'left',
layout: 'fit',
data: points,
title: '<span style="font-weight: bold;font-size:20px;">Events</b>',
flex: 2
};

case 'stockss':
return {
name: 'Stocks Available',
align: 'left',
data: stocks,
layout: 'fit',
title: '<span style="font-weight: bold;font-size:20px;">Price</b>',
flex: 1
};
case 'valuess':
return {
name: 'Value',
align: 'left',
data: values,
layout: 'fit',
title: '<span style="font-weight: bold;font-size:20px;">Trading style</b>',
flex: 2
};
}
}
});

我在这里创建了一个实例

var stockpicker = new Ext.StockPicker({});

当我使用 stockpicker.onShakeTap(); 时,我能够根据需要操作数据,但我在我的应用程序中使用相同的 stockpicker.onShakeTap(); html 页面无法正常工作。

请帮忙。

最佳答案

我会尝试类似的东西

var myStock = new Ext.Stocker();
myStock.onShakeTap();

onShakeTap() 被定义为 Ext.Stocker 类的一个方法。我假设它应该是一个成员方法,而不是静态的,因此您首先需要创建一个 Ext.Stocker 的实例。

关于javascript - 如何访问javascript文件中的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4827029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com