1

我有一些使用 codeigniter 的 PHP 代码。如何检查标记为检查的字段的验证?我的代码如下。

您能否让我知道如何检查项目是否已检查并相应地强制验证?

<html>

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <script type="text/Javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>/site.css"></link>
</head>

<body>

    <script type="text/Javascript">

        $(function () {
            $('.checkall').click(function () {
                $(this).parents('fieldset:eq(0)').
                    find(':checkbox').attr('checked', this.checked);
            });
        });

    </script>

    <? $attributes = array('class' => '', 'id' => ''); ?>

    <? echo form_open('ShoppingListController', $attributes); ?>

    <div class="divTable">

        <fieldset>
            <!-- these will be affected by check all -->
            <div class="divRow">Product Name | Quantity | Packages</div>
            <div class="divRow"><input type="checkbox" size="100" class="checkall"> Check all</div>


            <br>

                <?php foreach ($records as $rec) {
                    ?>

                    <div class="divRow"><input type="checkbox">
                            <input size="5" type="hidden" value="<? echo $rec->id; ?>" name="id"></input>
                            <input size="20" type="text" value="<? echo $rec->name; ?>" name="name"></input>
                            <label for="quantity">Value <span class="required">*</span></label>
                            <span class="required"><?php echo form_error('quantity'); ?></span>
                            <input size="5" type="text" value="" name="quantity"></input>

                            <select name="package">
                                <option name="case">Case</option>
                                <option name="box">Box</option>
                                <option name="box">Single Bottle</option>
                            </select>
                    </div>                
                    <br> 
                        <?
                    }
                    ?>


                    </fieldset> 
                    </div>
                    <div><input type="submit" name="submit"/></div>
                    </form>



                    </body>
4

1 回答 1

0

您可以使用以下代码:

var divRows = $('.divRow');
var count = divRows.length;

divRows.each(function() {
   if ($(this).find('input[type=checkbox]').is(':checked')) {
       count--;
   }
});
if (count != 0) {
   alert(count + ' checkboxes not checked');
}

http://jsfiddle.net/SKgA8/

于 2013-03-17T20:09:04.197 回答