var InputChange ={
total:0 ,
buytotal:0 ,
price:{},
changeGrain:function (){
var perperice = price[0];
var count = parseInt(document.getElementById("constGrain").value);
buyTotal += parseInt(perperice*count +1);
if(!isNaN(count)){
total -= perperice*count;
document.getElementById("Graintotal").innerHTML = parseInt(perperice*count +1);
} },
changeWood:function (){
var perperice = price[0];
var count = parseInt(document.getElementById("constWood").value);
buyTotal += parseInt(perperice*count +1);
if(!isNaN(count)){
total -= perperice*count;
document.getElementById("Woodtotal").innerHTML = parseInt(perperice*count +1);
} },
changeStone:function (){
var perperice = price[0];
var count = parseInt(document.getElementById("constStone").value);
buyTotal += perperice * count;
if(!isNaN(count)){
total -= perperice*count;
document.getElementById("Stonetotal").innerHTML = parseInt(perperice*count +1);
} },
changeIron:function (){
var perperice = price[0];
var count = parseInt(document.getElementById("constIron").value);
buyTotal += perperice * count;
if(!isNaN(count)){
total -= perperice*count;
document.getElementById("Irontotal").innerHTML = parseInt(perperice*count +1);
}
},
changeShow:function(){
document.getElementById("alltotal").innerHTML = parseInt(total);
document.getElementById("buyTotal").innerHTML = praseInt(buyTotal);
}
};
var price =[<s:iterator value="tradeList" var="value" status="of" end="endvar">${standardPrice}<s:if test="#of.last"></s:if><s:else>,</s:else>
</s:iterator>];
document.getElementById('constGrain').onkeyup = all;
document.getElementById('constWood').onkeyup = all;
document.getElementById('constStone').onkeyup = all;
document.getElementById('constIron').onkeyup = all;function all(){
var total = parseInt( document.getElementById("cityTotalGold").innerHTML);
var buyTotal =0 ;
var inputChange = new InputChange();
inputChange.property.total = total;
inputChange.property.buyTotal = buyTotal;
inputChange.property.price= price ;
inputChange.changeGrain;
inputChange.changeWood;
inputChange.changeIron;
inputChange.changeStone;
inputChange.changeShow;}
这是我写的一段脚本 我在new inputchange 对象的时候 firebug报错说 var inputChange = new InputChange(); 这行出错 , 说 InputChange(); 这个不是构造函数 咋办?
total:0 ,
buytotal:0 ,
price:{},
changeGrain:function (){
var perperice = price[0];
var count = parseInt(document.getElementById("constGrain").value);
buyTotal += parseInt(perperice*count +1);
if(!isNaN(count)){
total -= perperice*count;
document.getElementById("Graintotal").innerHTML = parseInt(perperice*count +1);
} },
changeWood:function (){
var perperice = price[0];
var count = parseInt(document.getElementById("constWood").value);
buyTotal += parseInt(perperice*count +1);
if(!isNaN(count)){
total -= perperice*count;
document.getElementById("Woodtotal").innerHTML = parseInt(perperice*count +1);
} },
changeStone:function (){
var perperice = price[0];
var count = parseInt(document.getElementById("constStone").value);
buyTotal += perperice * count;
if(!isNaN(count)){
total -= perperice*count;
document.getElementById("Stonetotal").innerHTML = parseInt(perperice*count +1);
} },
changeIron:function (){
var perperice = price[0];
var count = parseInt(document.getElementById("constIron").value);
buyTotal += perperice * count;
if(!isNaN(count)){
total -= perperice*count;
document.getElementById("Irontotal").innerHTML = parseInt(perperice*count +1);
}
},
changeShow:function(){
document.getElementById("alltotal").innerHTML = parseInt(total);
document.getElementById("buyTotal").innerHTML = praseInt(buyTotal);
}
};
var price =[<s:iterator value="tradeList" var="value" status="of" end="endvar">${standardPrice}<s:if test="#of.last"></s:if><s:else>,</s:else>
</s:iterator>];
document.getElementById('constGrain').onkeyup = all;
document.getElementById('constWood').onkeyup = all;
document.getElementById('constStone').onkeyup = all;
document.getElementById('constIron').onkeyup = all;function all(){
var total = parseInt( document.getElementById("cityTotalGold").innerHTML);
var buyTotal =0 ;
var inputChange = new InputChange();
inputChange.property.total = total;
inputChange.property.buyTotal = buyTotal;
inputChange.property.price= price ;
inputChange.changeGrain;
inputChange.changeWood;
inputChange.changeIron;
inputChange.changeStone;
inputChange.changeShow;}
这是我写的一段脚本 我在new inputchange 对象的时候 firebug报错说 var inputChange = new InputChange(); 这行出错 , 说 InputChange(); 这个不是构造函数 咋办?
var InputChange = function (){
...
}or
2、 直接使用.的方法找到里面的方法和变量
InputChange.changeShow();
alert(InputChange.total);
var InputChange{
...
}
已经是一个对象了,怎么还能new。
应该像1楼那张直接调用内部属性。var obj={};
function func() {
}
alert(typeof obj);//object
alert(typeof func);//function
alert(typeof new func());//object你的InputChange类似这里的obj,自然不能new。
好好看看js面向对象,简单的改成:var InputChange = function (){
...
}也不行,这样里面的语法结构不对
var struct={
a:'aa',
b:'bb'
}
alert(struct.a);
var fun=function(){
var a='aa';
this.b='bb';
}
var fun1=new fun();
alert(fun1.b);