Javascript没有更新样式

时间:2013-06-03 22:33:31

标签: javascript html css

为什么这不起作用? localStorage.fontSize包含正确的值,但第一个document.body.style.fontSize = localStorage.fontSize + "pt";不会更新样式。

<script type="text/javascript">

if(!localStorage.fontSize){
    localStorage.fontSize = Number(11); 
}
else{
    document.body.style.fontSize = localStorage.fontSize + "pt"; /* This row doesnt run */
}

function resetFont(){
    localStorage.fontSize = Number(11);
    document.body.style.fontSize = "11pt";
}
function enlargeFont(){
    localStorage.fontSize++;
    document.body.style.fontSize = localStorage.fontSize + "pt"; /* But this does if called */
}

</script>

请不要使用jQuery代码段。

0 个答案:

没有答案