我試圖訪問js文件中的一個函數文本單擊按鈕如何訪問它?如何訪問javascript文件中的函數?
這裏是我的html,也是js文件的代碼....
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']});
我要訪問的onShakeTap ()函數在索引頁面的stocking.js文件中。 請幫忙...
謝謝。
這裏是一些額外的數據:
我實際上延長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頁面它不工作..
p幫助!!!!
謝謝..這是現在能夠訪問的功能,但它不是回饋期望的結果.....可能是由於你剛纔給出的原因......我如何創建的實例它.....請原諒我的無知我只是一個首發.... – 2011-01-28 10:32:16