简体   繁体   中英

What am I missing here? (Javascript screen.width)

I have no idea what I'm missing here. I want to make a javascript, that responds to screen resolution, but I can't get it to work. Any input?

<SCRIPT LANGUAGE="javascript">

if (screen.width <= 479) 
{document.write("Less tgab 479");}


if (screen.width <= 480 && <= 767)
{document.write("Between 480 and 767")}


if (screen.width <= 768 && <= 989)
{document.write("Between 768 and 989")}


if (screen.width >= 990)
{document.write("Above 990")}

</SCRIPT>

All help are appreciated.

This should work

if (screen.width <= 479) {document.write("Less tgab 479");}

if (screen.width >= 480 && screen.width <= 767) {document.write("Between 480 and 767")}

if (screen.width >= 768 && screen.width <= 989) {document.write("Between 768 and 989")}

if (screen.width >= 990) {document.write("Above 990")}

The problem was you had wrong conditions in the second and third if

screen.width >= 480 && screen.width <= 767

screen.width >= 768 && screen.width <= 989

Your shorthand for the ands doesn't work, you have to explicitly write each condition out. Also you got the first condition backwards

from this:

if (screen.width <= 480 && <= 767)
{document.write("Between 480 and 767")}

to this:

if (screen.width >= 480 && screen.width < 768)
{document.write("Between 480 and 767")}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM