开发者

Why doesn't my if-else statement work?

Can anyone see why this does not work:

<script>
  if (url==showbasket.html||o开发者_JS百科rder1.html||order2.html||order3.html||order4.html) {
     document.write('<span style="font-family:lucida;font-size:10px;">Hello</span>');
  } else {
     document.write('<span style="font-family:lucida;font-size:30px;">Hello Hello</span>');
  }
</script>

I´m trying to write a script that do this:

IF URL = 1.html or 2.html or 3.html or 4.html THEN 
    write option1 
ELSE 
    write option2 (for all other URL´s)


if (url == "showbasket.html" || url == "order1.html" || url == "order2.html" || url == "order3.html" || url == "order4.html")

You have to do the check for each url and if it's a string use quotes


I don't think you got your if condition right:

if (url == showbasket.html || url == order1.html || ...


This code is valid, but it will not do what you want

if (url==showbasket.html||order1.html

"url==showbasket.html" checks if "url" is equal to the "html" attribute of object "showbasket". Since showbasket does not exist, your code will throw an exception.

"||order1.html" means the same, check if the "html" attribute of "order1" object is "true"

Like others have said, what you want to do is :

if ( url == "showbasket.html" || url == "order1.html"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜