2013-03-26 30 views
0

我这个简单的格式化功能:无法获取我的JavaScript函数?

function Forma(x, y): { 
var handler = function(e) { 
    document.getElementById(x).innerHTML = Number(this.value * 100).toLocaleString() + " Centimes"; 
}; 
document.getElementById(y).onchange = handler; 
document.getElementById(y).onkeyup = handler; 
} 

,并把它命名为formatter.js

现在,我尝试使用它的HTML页面,在开始加载:

<script src="path/to/formatter.js"></script> 

它加载它确定!但是当我把它放在:

<input id="price"> 
<script> 
Forma("hhh", "price"); 
</script> 
<h1 id="hhh" > </h1> 

控制台说Forma没有定义!

回答

2

的问题是在函数声明结肠

function Forma(x, y) { 
    ... 
} 

// or 
Forma = function(x, y) { 
    ... 
} 

应该正常工作

+0

对不起,蟒蛇习惯;) – 2013-03-26 22:45:36

+0

证实,它的工作,必须验证仅11分钟:( – 2013-03-26 22:46:20

+1

@AbdelouahabPp高兴以帮助 – 2013-03-26 22:47:37