复选框内部按钮? [英] Checkbox inside button?

查看:118
本文介绍了复选框内部按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以在按钮内获得一个复选框?

Is there any way to get a checkbox inside a button?

目前,我有以下解决方案:

At the moment I have this solution:

<html>
<body>
   <div id="menu">
     <button><input type="checkbox" /></button>
   </div>
</body>
</html>

没关系,它可以在Chrome和Firefox上正常工作...但是对于IE来说确实很糟糕,所以我需要另一种方法来实现这一目标.

It's ok, it works fine with Chrome and Firefox...but really awful with IE, so I need another way to achieve this goal.

有什么想法吗? 谢谢

推荐答案

我不确定您要在这里实现什么,因此,如果我的答案不是您想要的,请原谅我.如果您想要一个可以更改复选框状态的按钮,那么@thecodeparadox的答案应该很好用,但是,如果您正在寻找一个既执行功能又在其中具有可切换复选框的按钮,则可能需要类似于以下内容:

I'm not entirely sure what you're trying to achieve here, so please forgive me if my answer isn't what you were looking for. If you want a button which changes the state of a checkbox, then @thecodeparadox's answer should work great, however if you're looking for a button which performs a function but also has a checkbox inside of it which can be toggled, you might want something like the following:

HTML:

<div id="button" href="#">
    <input type="checkbox" class="check">Submit
</div>​

CSS:

body {
    margin: 10px;
}
#button {
    display: inline-block;
    background: #ddd;
    border: 1px solid #ccc;
    padding: 5px 10px;
    text-decoration: underline;
    color: blue;
    cursor: pointer;
}
.check {
    display: inline-block;
    margin-right: 10px;
}

jQuery:

$('#button').on('click', function() {
    window.location = '#';
})​

http://jsfiddle.net/QStkd/278/

这篇关于复选框内部按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆