美好的一天,
我在javaScript文件中有一个函数。我有10个按钮会触发此功能,根据按钮名称执行某些操作。代码如下:
function doSomething( name ){
switch(name){
case "1";
alert("i am 1");
break;
case "2";
alert("i am 1");
break;
// and so on...
}
}
此doSomething
工作正常。但是,如果noscript
或JavaScript
处于禁用状态,我想提醒其他事项。
我做的事情如下:
<noscript>
// if click on button 1, display <image src="image/img1" />
// if click on button 2, display <image src="image/img2" />
// and so on..
// I would like display different image when different button clicked.
</noscript>
请告知。
答案 0 :(得分:0)
没办法。 HTML5本身只是一个文档结构,CSS3提供了样式。也就是说,HTML5 as 没有任何行为,因此,如果没有JavaScript,您将无法与文档进行交互。
如果禁用了JavaScript并且您提供了<noscript>
元素,则应该告诉您的用户,如果没有JavaScript,您的Web应用程序将无法运行。
答案 1 :(得分:0)
您可以执行类似css中的复选框hack以在隐藏的div中显示消息,将标签设置为按钮的样式。
input[type=checkbox] {
position: absolute;
top: -9999px;
left: -9999px;
}
label {
background: #08C;
padding: 5px;
border: 1px solid rgba(0,0,0,.1);
border-radius: 2px;
color: white;
font-weight: bold;
}
.to-be-changed {display:none;}
input[type=checkbox]:checked ~ .to-be-changed {
display:block;
margin-top:30px;
font-size:120%;
color:red;
}
&#13;
<noscript>
<div id="buttons">
<input type="checkbox" id="button1"><label for="button1">button 1</label>
<input type="checkbox" id="button2"><label for="button2">button 2</label>
<input type="checkbox" id="button3"><label for="button3">button 3</label>
<div class="to-be-changed"> You need to have javascript activated for the buttons to work !</div>
</div>
</noscript>
&#13;
显然将js关闭以使其正常工作。这是指向我从Css click events
获取信息的页面的链接