javascript - 样式复选框

标签 javascript html css

我正在尝试插入图像而不是选中复选框。正在使用的代码是:

<html>
<head>
<style>
.bl {
background:-webkit-gradient(linear, left top, left bottom, color-stop(0, #175899), color-stop(0.5, #7da4bf), color-stop(3, #9fbed3));
width: 90%;
height:30px;
border-radius: 5px;
margin-right:auto;
margin-left:auto;
margin-top:10px;
margin-bottom:10px;
}
p
{
font-family:"Times New Roman";
font-size:10px;
}

checkbox
{
  width: 75px;
  height: 75px;
  padding: 0 5px 0 0;
  background: url(images/Green_tick.png) no-repeat;
  display: block;
  clear: left;
  float: left;
}

.checked {
  position: absolute;
  width: 200px;
  height: 21px;
  padding: 0 24px 0 8px;
  color: #fff;
  font: 12px/21px arial,sans-serif;
  background: url(images/Green_tick.png) no-repeat;
  overflow: hidden;
}

</style>
</head>

<body>
<script>
function Checked(id)
{
if(id.checked==1)
{
    alert("Checked");
}
else
{
    alert("You didn't check it! Let me check it for you.")
        id.checked = 1;

}
}

</script>

<div class="main_menu">
    <a id='menu' href="javascript:" onclick="loadMenuPage();"></a>
</div>
<p>
All verifications required for QR7 can be uploaded here. Any item which still requires verification is
marked in red until picture has been attached.
</p>
<div class="bl">  
<input type="checkbox" id="checkbox" class="checkbox" onclick="Checked(id);"> Income </input>
</div>
<div class="bl">  
<input type="checkbox" id="checkbox" class="checkbox" onclick="Checked(id);"> Property </input>
</div>
<div class="bl">  
<input type="checkbox" id="checkbox" class="checkbox" onclick="Checked(id);"> Court Order Child Support </input>
</div>
<div class="bl">  
<input type="checkbox" id="checkbox" class="checkbox" onclick="Checked(id);"> Future Medical Child Support </input>
</div>

</body>
</html>

关于我如何实现它的任何建议。截至目前,我在复选框中得到一个正常的勾号。

提前致谢。

最佳答案

这篇文章很旧,但这是我的建议:

像这样将标签关联到您的复选框:

<input type="checkbox" value="1" id="c1" />
<label class="check" for="c1"></label>

通过 css 隐藏您的复选框:

.checkboxes input[type=checkbox]{
    display:none
}

根据需要设置标签的样式。我创建了一个简单的 jsfiddle,它充分演示了如何使用个性化复选框。我在此示例中使用背景色,但您可以轻松地改用背景图片。

Here是 jsfiddle

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

相关文章:

javascript - 如何使HTML按钮执行 Electron JS功能

javascript - 保存具有 id 的元素的变量存储在哪里?

javascript - 尝试通过自定义扩展从 Google Chrome 上下文菜单启动 JNLP

html - Bootstrap 下拉菜单不起作用(不显示下拉列表)

javascript - CSS 属性用图像填充父 div,居中,并更改大小以填充父级

javascript - Zurb Foundation - 下拉菜单不起作用

css - 如何将 sifr 规则应用于超链接及其对应的 a.active

javascript - 在ajax成功方法中返回未定义

javascript - Jquery 的问题相当于 javascript createElement

javascript - ReactJS:加载组件时 'type is undefined'