javascript - CSS 样式

标签 javascript css stylesheet

我正在为一个网站提出问题,并希望 var reltext 中的正确/再试消息具有不同的颜色,即绿色表示正确,红色表示错误,并且每个旁边可能有一个小 png。

有什么想法吗?

<form name = "Q1">
  <p>A local construction company has purchased 5 brand new diggers. Two of them have a telescopic jib. If a driver chooses a digger to use at random what is the probability it will have a telescopic jib?<br>

    0/5 
  <input name = "rad1" type = "radio" class="radio" onclick = "getAnswer('1a', '1')">
    1/5 
  <input name = "rad1" type = "radio" class="radio" onclick = "getAnswer('1b', '2')">
    2/5 
  <input name = "rad1" type = "radio" class="radio" onclick = "getAnswer('1c', '3')">
    3/5 
  <input name = "rad1" type = "radio" class="radio" onclick = "getAnswer('1d','4')">
  <br><br>
  </p>
<div id = "para"><div>
</form>

<script type = "text/javascript">
var reltext = [];
reltext[1] = "TRY AGAIN - 0/5 This would mean that there was no diggers with a telescopic jib." 
reltext[2] = "TRY AGAIN - 1/5 This would mean that there was only 1 digger with a telescopic jib"
reltext[3] = "CORRECT - 2/5 This would mean that there was 2 diggers with a telescopic jib" 
reltext[4] = "TRY AGAIN - 3/5 This would mean that there was 3 diggers with a telescopic jib."

function getAnswer(ans, rel) {
document.getElementById("para").innerHTML = reltext[rel];
if (ans == "1c") {alert ("Correct - Well done!")}
else {alert ("Incorrect - Try again")}
}

</script>

最佳答案

您不得使用 JavaScript(或与此相关的任何其他内容)设置警告框内容的样式。

一个不错的选择是使用像 jQuery UI 这样的框架,并使用模态对话框而不是 JS 警报。这是 jQuery UI 对话框的链接:http://jqueryui.com/demos/dialog/

关于javascript - CSS 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9806793/

相关文章:

html - 如何按高度拉伸(stretch)图像?

html - CSS:对齐和换行文本

CSS 随机填充

html - 在媒体 ='print' css 文件中使用@media 和@page 的目的是什么

ios - iOS:适用于iOS应用的样式表/主题

javascript - 如何在 Extjs 3.2 上使用卡片布局创建高级向导表单?

javascript - 如何使用 Ajax 将图像添加到 MySQL

html - Div的高度响应

javascript - 如何用正则表达式替换 Javascript 中的 "value"?

javascript - 拉斐尔悬停错误?