显示没有JavaScript的内容

时间:2015-05-06 05:01:07

标签: javascript jquery html css

有什么方法可以在禁用JavaScript时使用jQuery / JavaScript的网页内容?

当我点击div标签的h2标题信息时,将使用jQuery函数显示。我已经包含了一个noscript标签来显示javaScript被禁用。在关闭javaScript时,我可以从标题显示中获取信息吗?

谢谢

<h1>CLICK ON AN ITEM TO VIEW INFORMATION (Scroll down to view)</h1>
<h2 data-type="pizza">Pizza</h2>
<h2 data-type="sandwich">Sandwiches</h2>
<h2 data-type="other">Other Items</h2>
<h2 data-type="beverage">Beverages</h2>

 <div id="pizza" class="hidden">
 <h3>PIZZA </h3>
 <hr>
 <br>
 <p>
 <strong>Classic:</strong> 
 Beef, Pepperoni, Onions & Mushrooms &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 (10")$11.40 &nbsp; (12") $14.55
 </p>
 <p>
 <strong>Palace:</strong>
 Sausage, Beef, Pepperoni, Onions & Mushrooms&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 (10")&nbsp$11.40 &nbsp; (12") $14.55
 </p>
 <p>
 <strong>Philly Steak:</strong>
 Seasoned Steak with Onions, Green Peppers on our Special White Sauce &nbsp (10") $11.40 &nbsp; (12") $14.55 

 </p>
 <p>
 <strong>"B" Special:</strong>
 Sausage, Salami, Canadian Bacon & Onions &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 (10")&nbsp$11.40 &nbsp; (12") $14.55
 </p>
 <p>
 <strong>Maverick:</strong>
 Sausage, Beef, Canadian Bacon & Pepperoni &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 (10") $11.40 &nbsp; (12") $14.55
 </p>
 </div>

(document).ready(function(){
  $("h2").on('click', function(){
  var id = $(this).attr("data-type");
  $(".hidden").hide();
  $("#"+id+"").toggle();
  });
});

<noscript>
YOUR BROWSER DOES NOT SUPPORT JAVASCRIPT!
</noscript>

2 个答案:

答案 0 :(得分:3)

解决方案:在考虑Progressive Enhancement的情况下,从头开始开发您的网站。

您可以在您的情况下应用此方法,将h2标记替换为锚标记,锚标记链接到其他网页上的div内容。对于启用了javascript的客户端,请点击这些锚点上的点击并显示预先存在的隐藏内容,或使用ajax动态加载它们。

答案 1 :(得分:1)

继上面我的评论是 答案:

您可以在noscript标记中放置重定向,以重定向到非js相关内容。

<noscript>
    <meta http-equiv="refresh" content="0; url=http://yourwebsite.com/your-alternative-content/" />
</noscript>`