想要计算租约的剩余年限吗?
简而言之,计算是:
Var today = the current Year (eg. 2019)
Var year = the current record LeaseYear (eg. 1995)
Var term = the current record LeaseTerm (eg. 125)因此:
左=期限-(今天-年)
或
左= 125-(2019-1995)
当我意识到我需要做的事情(在页面字段的绑定区域中使用表达式,或者调用脚本)时,我还处于学习阶段,但我不太擅长语法。
我非常感谢这里的一个指针,这样我就可以用这一课做更复杂的事情。
谢谢
发布于 2019-04-09 22:58:12
作为函数表达式
var calc = function(term, today, year) {
return term - (today - year);
};
var result = calc(125, 2019, 1995);
// Let's render it to HTML
var htmlElement = document.getElementById("some-id");
htmlElement.innerText = result;#some-id {
color: red;
font-weight: bold;
}<p>Solution: <span id="some-id"></span></p>
作为函数声明
function calc(term, today, year) {
return term - (today - year);
};
var result = calc(125, 2019, 1995);
// Let's render it to HTML
var htmlElement = document.getElementById("some-id");
htmlElement.innerText = result;#some-id {
color: red;
font-weight: bold;
}<p>Solution: <span id="some-id"></span></p>
作为箭头函数(ES6)
const calc = (term, today, year) => term - (today - year);
const result = calc(125, 2019, 1995);
// Let's render it to HTML
const htmlElement = document.getElementById("some-id");
htmlElement.innerText = result;#some-id {
color: red;
font-weight: bold;
}<p>Solution: <span id="some-id"></span></p>
希望能有所帮助。干杯!
https://stackoverflow.com/questions/55571946
复制相似问题