使用chrome的开发工具,我可以看到我的index.xhtml显示状态200OK,但当我点击我的转换按钮时,转换后的金额没有显示出来。下面是我的xhtml文件:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Currency Exchange Rate Calculator</title>
<meta charset="utf-8"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="money.js"></script>
<script src="accounting.js"></script>
<script src="http://openexchangerates.org/api/latest.json?app_id=e6b775e4bbde4ae19dd7294c39d71b15"></script>
<script src="http://openexchangerates.org/api/currencies.json?app_id=e6b775e4bbde4ae19dd7294c39d71b15"></script>
<script src="http://openexchangerates.org/api/historical/2011-10-18.json?app_id=e6b775e4bbde4ae19dd7294c39d71b15"></script>
<link rel="StyleSheet" type="text/css" href="apricot.css"></link>
<script type="text/javascript">
// Load exchange rates data via the cross-domain/AJAX proxy:
$(document).ready(function () {
function load(){
$.getJSON(
'http://openexchangerates.org/latest.json?app_id=e6b775e4bbde4ae19dd7294c39d71b15',
function(data) {
// Check money.js has finished loading:
if ( typeof fx != "undefined") {
fx.rates = data.rates;
fx.base = data.base;
alert("fx loaded");
} else {
// If not, apply to fxSetup global:
alert("fx not loaded");
var fxSetup = {
rates : data.rates,
base : data.base
}
}
}
).error(function(error){console.log(error);});
return false;
}
});
function convert(){
//load();
var fromelement = document.getElementById('xrate:fromcur');
var from=fromelement.value;
var toelement = document.getElementById('xrate:tocur');
var to = toelement.value;
var amtelement =document.getElementById('xrate:amt');
var amt = amtelement.value;
alert("from = "+from+" to = "+to+" amount = "+amt);
//fx.settings = { from: from, to: to };
var conv=fx.convert(amt,{ from: from, to: to });
alert("conv = "+conv);
//fx.settings = { from: from, to: to };
//var conv=fx.convert(amt); // 647.71034
var convelement = document.getElementById('xrate:result');
convelement.value=conv;
}
</script>
</h:head>
<h:body>
<div id="welcome">
<h:form id="xrate">
<h:panelGrid columns="2" style="background-color: yellow">
<h:outputLabel value="Select Currency From" for="fromcur" />
<h:selectOneListbox id="fromcur" size = "1" value="xxx" title="xxx" >
<f:selectItem id="si0" itemLabel=" " itemValue=" " />
<f:selectItem id="si1" itemLabel="RON" itemValue="RON" />
<f:selectItem id="si2" itemLabel="EUR" itemValue="EUR" />
<f:selectItem id="si3" itemLabel="CAD" itemValue="CAD" />
<f:selectItem id="si4" itemLabel="GBP" itemValue="GBP" />
<f:selectItem id="si5" itemLabel="USD" itemValue="USD" />
<f:selectItem id="si6" itemLabel="MXP" itemValue="MXP" />
<f:selectItem id="si7" itemLabel="CNY" itemValue="CNY" />
</h:selectOneListbox>
<h:outputLabel value="Select Currency To" for="tocur" />
<h:selectOneListbox id="tocur" size = "1" value="xxx" title="xxx" >
<f:selectItem id="ti0" itemLabel=" " itemValue=" " />
<f:selectItem id="ti1" itemLabel="RON" itemValue="RON" />
<f:selectItem id="ti2" itemLabel="EUR" itemValue="EUR" />
<f:selectItem id="ti3" itemLabel="CAD" itemValue="CAD" />
<f:selectItem id="ti4" itemLabel="GBP" itemValue="GBP" />
<f:selectItem id="ti5" itemLabel="USD" itemValue="USD" />
<f:selectItem id="ti6" itemLabel="MXP" itemValue="MXP" />
<f:selectItem id="ti7" itemLabel="CNY" itemValue="CNY" />
</h:selectOneListbox>
<h:outputLabel value="Enter Amount" for="amt" />
<h:inputText id="amt" style="color:red;background- color:yellowgreen" size="10"/>
<h:commandButton value="Calculate" id="calc" onclick="convert()"/>
<h:outputText id ="result" style="color:blue;border:5px solid tan;" />
</h:panelGrid>
</h:form>
</div>
</h:body>
</html>
enter code here我正在使用openexchangerates.org的链接,任何帮助都将不胜感激。谢谢。
发布于 2013-12-19 23:54:04
我在代码中发现了错误。因此,对于任何感兴趣的人来说,现在可以很好地使用它:
<script type="text/javascript">
// Load exchange rates data via the cross-domain/AJAX proxy:
// $(document).ready(function () {
$.getJSON(
'http://openexchangerates.org/latest.json?app_id=e6b775e4bbde4ae19dd7294c39d71b15',
function(data) {
// Check money.js has finished loading:
if ( typeof fx != "undefined") {
fx.rates = data.rates;
fx.base = data.base;
//alert("fx loaded");
} else {
// If not, apply to fxSetup global:
//alert("fx not loaded");
var fxSetup = {
rates : data.rates,
base : data.base
}
}
}
)
// });
function convert(){
//load();
var fromelement = document.getElementById('xrate:fromcur');
var from=fromelement.value;
var toelement = document.getElementById('xrate:tocur');
var to = toelement.value;
var amtelement =document.getElementById('xrate:amt');
var amt = amtelement.value;
alert("from = "+from+" to = "+to+" amount = "+amt);
//fx.settings = { from: from, to: to };
var conv=fx.convert(amt,{ from: from, to: to });
alert("conv = "+conv);
//fx.settings = { from: from, to: to };
//var conv=fx.convert(amt); // 647.71034
var convelement = document.getElementById('xrate:result');
convelement.value=conv;
//document.getElementById('xrate:result').value=conv;
}发布于 2020-04-08 03:36:33
从money //React组件导入外汇
handleSubmit(){
/*require(["money"], function(fx) {
console.log(fx.convert(1000, {from: "GBP", to: "HKD"}))
})*/
fx.base = "USD";
fx.rates = {
"EUR" : 0.745101, // eg. 1 USD === 0.745101 EUR
"GBP" : 0.647710, // etc...
"USD" : 1, // always include the base rate (1:1)
/* etc */
}
console.log(fx(1.99).from("USD").to("GBP"))
}https://stackoverflow.com/questions/20640789
复制相似问题