开发者

Display message if Javascript doesn't work?

What is the simplest way to display a note in place of what the script would normally output?

I currently have the following code:

<p id="orderBy">
<script type="text/javascript"> 
  <!-- 
  // Array of day names
  var dayNames = ["Sunday","Monday","Tuesday","Wednesday",
                "Thursday","Friday","Saturday"];
  var nextWorkingDay = [ 1, 2, 3, 4, 5, 1, 1 ];
  var now = new Date();
  document.write("Order by 5pm today for dispatch on " +
     开发者_如何学Python            dayNames[nextWorkingDay[now.getDay()]]);
  // -->
</script>
</p>

(as per Display tomorrow's name in javascript?)

As an example, the above code outputs the following:

Order by 5pm today for dispatch on Monday

I would like to have the following if for any reason javascript is disabled:

Order by 5pm for next working day dispatch

How can I do this?


Use either<noscript>:

<noscript>
    Order by 5pm for next working day dispatch
</noscript>

or put the text into a normal element and hide it with JavaScript.


<p id="orderBy">
<script type="text/javascript"> 
  <!-- 
  // Array of day names
  var dayNames = ["Sunday","Monday","Tuesday","Wednesday",
                "Thursday","Friday","Saturday"];
  var nextWorkingDay = [ 1, 2, 3, 4, 5, 1, 1 ];
  var now = new Date();
  document.write("Order by 5pm today for dispatch on " +
                 dayNames[nextWorkingDay[now.getDay()]]);
  // -->
</script>
<noscript>Order by 5pm for next working day dispatch</noscript>
</p>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜