admin管理员组文章数量:1435859
I am looking for a way to allow for the user to select multiple months, days, hours and minutes where this will be used for scheduling tasks. The easiest way I can imagine doing this is using checkboxes for each element since they have a boolean properly I can use to determine if its selected or not.
In using this approach, I would like to either entire replace the checkbox with an image (different image for checked/unchecked) or just hide the existing image and style the text area to give the effect of an image using CSS.
How can I replace the default checkbox with an image or hide the default checkbox image entirely?
Example:
I am looking for a way to allow for the user to select multiple months, days, hours and minutes where this will be used for scheduling tasks. The easiest way I can imagine doing this is using checkboxes for each element since they have a boolean properly I can use to determine if its selected or not.
In using this approach, I would like to either entire replace the checkbox with an image (different image for checked/unchecked) or just hide the existing image and style the text area to give the effect of an image using CSS.
How can I replace the default checkbox with an image or hide the default checkbox image entirely?
Example:
Share Improve this question asked Apr 23, 2015 at 22:50 user470760user4707604 Answers
Reset to default 2toggleClass() does this sort of thing:
http://jsfiddle/zsxyequj/
$('.btn').click(function() {
$('.btn').toggleClass('col');
});
You can use a <label>
for your checkbox and then hide it using CSS. Something like this should work:
HTML
<input type="checkbox" id="check" class="checkbox">
<label for="check"><img src="..."/></label>
CSS
input {
display:none;
}
Anything you put inside the <label>
tags will activate that checkbox when clicked.
Here is a fiddle of it in action. If you remove the display:none;
you'll notice that clicking on the label contents checks the box.
http://jsfiddle/w61zb19y/
The advanced checkbox hack es to mind - this allows you to use a hidden checkbox to control an element to indicate on/off
In this example below, clicking the image changes the styles by which you can indicate selected or not
Here's one way to use it
HTML
<table id="calendar">
<tbody>
<tr>
<td>
<!-- duplicate this table cell as many times as needed but
give each input an id and update the label's for attributes -->
<label for="toggle-1"><img src="someimage.jpg"><!-- this can be an image, text whatever --></label>
<input type="checkbox" id="toggle-1">
<div>select</div>
</td>
</tr>
</tbody>
</table>
CSS
/* Checkbox Hack */
#calendar input[type=checkbox] {
position: absolute;
top: -9999px;
left: -9999px;
}
#calendar label {
-webkit-appearance: push-button;
-moz-appearance: button;
display: inline-block;
margin: 60px 0 10px 0;
cursor: pointer;
}
/* Default State */
#calendar div {
background: red;
width: 400px;
height: 100px;
line-height: 100px;
color: white;
text-align: center;
}
/* Toggled State */
#calendar input[type=checkbox]:checked ~ div {
background: green;
}
#calendar input[type=checkbox]:checked ~ div:after {
content: "ed"
}
And here's an example I put together after playing a little more where it doesn't look like a separate elements:
http://jsfiddle/8nz1k2wb/
It's something you can change to suit your needs
http://timpietrusky./advanced-checkbox-hack
you can't design the checkbox itself but you can hide it and use other element for the design, the design of the element will be changed by the checkbox situation. replace the design to whatever you like...
HTML:
<label class="checkbox">
<input type="checkbox" />
<span>option</span>
</label>
CSS:
.checkbox input[type="checkbox"]
{
display: none;
}
.checkbox span
{
display: inline-block;
width: 18px;
text-indent: 25px;
border: 1px solid;
}
.checkbox input[type="checkbox"]:checked + span
{
background: #ccc;
}
fiddle: http://jsfiddle/62ptgwee/1/
本文标签: javascriptReplace checkbox with image buttonStack Overflow
版权声明:本文标题:javascript - Replace checkbox with image button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745669501a2669486.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论