我試圖讓一個按鈕有兩個功能:如何更改JS中的布爾值?
function bigfont()
{var font_is_small = true
if (font_is_small = true)
{document.getElementById('one').className=
document.getElementById('one').className.replace("font1","font2");
document.getElementById('two').className=
document.getElementById('two').className.replace("font1","font2");
document.getElementById('three').className=
document.getElementById('three').className.replace("font1","font2");
document.getElementById('four').className=
document.getElementById('four').className.replace("font3","font4");
font_is_small = true;}
if(font_is_small = false)
{document.getElementById('one').className=
document.getElementById('one').className.replace("font2","font1");
document.getElementById('two').className=
document.getElementById('two').className.replace("font2","font1");
document.getElementById('three').className=
document.getElementById('three').className.replace("font2","font1");
document.getElementById('four').className=
document.getElementById('four').className.replace("font4","font3");
font_is_small = true;}}
但變量不發生改變。有人能幫助我嗎?
變化'如果(font_is_small =真)'來'如果(font_is_small === true)' – PeterVC 2014-12-06 18:55:11
在javaScript中,相等比較器是'=='或'===' – nha 2014-12-06 18:55:17
也看到這個SO帖子:http://stackoverflow.com/questions/359494/does-it-matter-which-equals - 操作員與我在使用的JavaScript比較 – nha 2014-12-06 18:56:20