javascript - jQuery 表单选择器 :input is excluding the :checked in chrome and firefox

标签 javascript jquery css google-chrome jquery-selectors

为什么 :checked 或输入类型复选框被排除?我正在尝试使用表单选择器选择所有输入。它在 Internet Explorer 中运行良好,但在 Chrome 或 Firefox 中运行不佳。这是代码:

<!DOCTYPE html>
<html>
<head>
    <title>Using Form Selectors and Filters</title>
<script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<script type="text/javascript">
    $("document").ready(function() {
        $('form :input').css('border', '3px solid red');
    });
</script>
    <style type="text/css">
        .style1{width: 600px;}
        .style2{width: 200px;}
    </style>
</head>
<body>
    <h1>Example Form Document</h1>
    <form action="" method="post">

        <table class="style1">
            <tbody>
                <tr>
                    <td class="style2">First Name</td>
                    <td><input id="FirstName" type="text" /></td>
                </tr>
                <tr><td class="style2">Last Name</td><td>
                        <input id="LastName" type="text" /></td>
                </tr>
                <tr><td class="style2">Disabled Text Field</td>
                    <td><input id="Text1" type="text" disabled="disabled"/></td>
                </tr>
                <tr><td class="style2">Gender</td>
                    <td><input id="Male" type="radio" checked="checked"/>M<input id="Female" type="radio" />F</td>
                </tr>
                <tr>
                    <td class="style2">What products are you interested in?</td>
                    <td>
                        <input id="Checkbox1" type="checkbox" checked="checked"/><label for="Checkbox1">Widgets</label><br />
                        <input id="Checkbox2" type="checkbox" /><label for="Checkbox1">Hibbity Jibbities</label><br />
                        <input id="Checkbox3" type="checkbox" checked="checked"/><label for="Checkbox1">SplashBangers</label><br />
                        <input id="Checkbox4" type="checkbox" /><label for="Checkbox1">Whatzits</label>
                    </td>
                </tr>
                <tr>                        
                    <td>
                        <input id="Submit1" type="submit" value="submit" /> <input id="Reset1" 
                            type="reset" value="reset" /></td>
                </tr>
            </tbody>
        </table>    
    </form>
</body>
</html>

我可以看到除了那些复选框外,所有输入都用红色边框突出显示。这可能是浏览器或 JavaScript 问题吗?我正在尝试学习 jquery 顺便说一下。

最佳答案

输入类型[复选框]不接受边框属性,也许你可以使用 大纲 或 [1]:http://www.no-margin-for-errors.com/projects/prettycheckboxes/ 用于自定义复选框

关于javascript - jQuery 表单选择器 :input is excluding the :checked in chrome and firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33472848/

相关文章:

jquery - 删除记录/数据后如何重新加载数据表?

jquery - Twitter Bootstrap : Want the alerts not moving the rest of the page down

HTML 标签文本内容替换为图标

c# - <td> 内的 Div 对齐

javascript - HTML Canvas - 随着内容的增长自动调整大小

javascript - Chrome 扩展中 CSS 注入(inject)期间闪烁

php - 如何在网页之间传递 '&amp;'数据

javascript - 表单验证只验证第一个字段

javascript - 文字转语音在 Android WebView 和 Firefox 中不起作用

javascript - 为什么单击提交按钮后会提交此表单