如果Javascript不起作用,显示消息?

时间:2011-01-31 12:21:30

标签: 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>
</p>

(根据Display tomorrow's name in javascript?

例如,上面的代码输出如下:

Order by 5pm today for dispatch on Monday

如果因为任何原因禁用了javascript,我想要以下内容:

Order by 5pm for next working day dispatch

我该怎么做?

2 个答案:

答案 0 :(得分:4)

使用<noscript>

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

或将文本放入普通元素并使用JavaScript隐藏它。

答案 1 :(得分:2)

<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>