在函数外部声明变量…
var oneVariable;
function setVariable(){
oneVariable = "Variable set from within a function!";
}
function getVariable(){
alert(oneVariable); // Outputs "Variable set from within a function!"
}
或者… 将其附加到窗口对象
function setValue() {
window.myValue = "test";
}
function getValue() {
alert(window.myValue); // "test" (assuming setValue has run)
}
在声明全局变量时,甚至不需要指定“var”。
使用“var”关键字是一种良好的实践。
声明全局变量是一种不好的实践…
好的,但有时它是绝对必要的。
我在 css 全局变量赋值方面遇到问题,这是正确的吗?但它不起作用,如何解决?
………………………
@D:280px;
@R:(@D/2); // radio
-webkit-@R:(@D/2); // radio
@B:(@R/8);
-webkit-@B:(@R/8);
@O: 0.6; // opacity
-webkit-@O: 0.6;
@A: 2s; // accelerate
-webkit-@A: 2s;
html,
body{
height: 100%;
}
body{
overflow: hidden;
}
.hoja{
color: rgb(220,220,226);
position:absolute;
top:50%; left:50%;
-webkit- margin-left:-@R;
margin-top:-@R;
width:@D;
height:@D;
text-align:center;
font-family: ‘Open Sans’, sans-serif;
font-size:@R/4;
line-height:@D;
-webkit-font-smoothing: antialiased;
}
…………………………..