解决 我没有使用" name"在输入字段中。当我为输入添加名称时,我立即工作。
我有一个中等大小的菜单,里面有几个子类别和很多复选框。我使用php,mysql和jquery / javascript开发自定义CMS。
菜单采用带按钮的形式" Save"需要从选中的复选框中获取所有值。
在按钮上,我使用onclick函数指向我的班级,在该班级中我使用这些id并将它们存储在表格中。
<input type="submit" value="Save" class="save-butt" onclick="sjx('domain', $( ':checkbox' ).serializeArray()); return false;">
它不起作用;我没有收到任何错误,但似乎没有发送该值。 如果它有帮助,这是我的菜单代码。
<div class="personal-right-box">
<ul class="doe-list">
<?php
$mainCat = Db::query('SELECT * FROM categories WHERE parent_id = 0 ORDER BY orderby DESC');
foreach ($mainCat as $main) { ?>
<li>
<span><i class="fa fa-caret-down toggle-down"></i><?php echo $main['title_hr']; ?></span>
<ul class="doe-list-sub">
<?php
$subCat = Db::query('SELECT * FROM categories WHERE parent_id = '.$main['id'].' ORDER BY title_hr ASC');
foreach ($subCat as $sub) { ?>
<li>
<input type="checkbox" name="" id="aaeroplanes-b1-b2" value="<?php echo $sub['id']; ?>">
<label for="aaeroplanes-b1-b2"><?php echo $sub['title_hr']; ?></label>
<i class="fa fa-caret-down toggle-down"></i>
<ul class="doe-list-sub">
<?php
$subsubCat = Db::query('SELECT * FROM categories WHERE parent_id = '.$sub['id'].' ORDER BY title_hr ASC');
foreach ($subsubCat as $subsub) { ?>
<li>
<input type="checkbox" name="" id="piston-engine-aeroplanes-b1-2" value="<?php echo $subsub['id']; ?>">
<label for="piston-engine-aeroplanes-b1-2"><?php echo $subsub['title_hr']; ?></label>
<i class="fa fa-caret-down toggle-down"></i>
<ul class="doe-list-sub">
<?php
$subsubsubCat = Db::query('SELECT * FROM categories WHERE parent_id = '.$subsub['id'].' ORDER BY title_hr ASC');
foreach ($subsubsubCat as $subsubsub) { ?>
<li>
<input type="checkbox" name="" id="cessna" value="<?php echo $subsubsub['id']; ?>">
<label for="cessna"><?php echo $subsubsub['title_hr']; ?></label>
<i class="fa fa-caret-down toggle-down"></i>
<ul class="doe-list-sub group">
<?php
$items = Db::query('SELECT * FROM categories WHERE parent_id = '.$subsubsub['id'].' ORDER BY title_hr ASC');
foreach ($items as $item) { ?>
<li class="col-1-3">
<input type="checkbox" name="" id="" value="<?php echo $item['id']; ?>">
<label for=""><?php echo $item['title_hr']; ?></label>
</li>
<?php } ?>
</ul>
</li>
<?php } ?>
</ul>
</li>
<?php } ?>
</ul>
</li>
<?php } ?>
</ul>
</li>
<?php } ?>
</ul><!-- end of .doe-list -->
<span class="save-button-form">
<input type="submit" value="Save" class="save-butt" onclick="sjx('domain', $( ':checkbox' ).serializeArray()); return false;">
</span>
</div>
感谢您的帮助。
答案 0 :(得分:1)
序列化首先使用name
,如果找不到,则会转到id
。在您的情况下,您有一个空白name
,结果也是如此。
您可以在name
中复制相同的内容或将其删除。