2013-05-05 65 views
1

我有一些:由wordpress初始化的复选框元素。现在,我设置.buttonset()函数来#format但这是不行的......这样的例子:http://jqueryui.com/button/#checkbox无法在jQuery上运行.buttonset()

HTML:

<div id="format"> 
    <?php 
    $categories = get_categories(); 
    foreach ($categories as $category) { ?> 
    <input type="checkbox" name="check" value="<?php echo $category->cat_ID; ?>"> 
    <label><?php echo $category->cat_name;?></label><?php } ?> 
    *//ADD STATIC HTML:* 
    <input type="checkbox" id="id" /><label for="id">B</label> 

</div> 

JS:

$('#format').buttonset(); 
$('input[type=checkbox]').removeClass('ui-helper-hidden-accessible'); 

$(':checkbox[name=check]').each(function(i){ 
    var nameID = 'check'+ (i+1); 
    this.id = nameID; 
    $(this).next('label').prop('for', nameID); 
}); 

如果我添加了一个静态HTML复选框元素,它运行良好。

<input type="checkbox" id="id" /><label for="id">U</label>

,这是生成的HTML:

<div id="format" class="ui-buttonset"> 
    <input type="checkbox" name="check" value="3" class="check" id="check1"> 
      <label for="check1"> 
      <span class="ui-button-text">CAT1</span> 
      </label>  
    <input type="checkbox" name="check" value="4" class="check" id="check3"> 
      <label for="check3"> 
      <span class="ui-button-text">CAT2</span> 
      </label>    
    <input type="checkbox" name="check" value="5" class="check" id="check4"> 
      <label for="check4"> 
      <span class="ui-button-text">CAT3</span> 
      </label>    
    <input type="checkbox" id="id" class=""> 
      <label for="id" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right ui-corner-left" role="button" aria-disabled="false" aria-pressed="false"> 
      <span class="ui-button-text">B</span></label> 

</div> 
+1

您不关闭您的标签。同样,'$('input [type = checkbox]')。removeClass('ui-helper-hidden-accessible');' – PSL 2013-05-05 05:26:33

+0

哪个输入元素? – pouya 2013-05-05 05:30:26

+0

PSL 2013-05-05 05:30:52

回答

0

你不闭上你的输入类型复选框,在你的PHP代码

<input type="checkbox" name="check" value="<?php echo $category->cat_ID; ?>"/> 
+0

看上去对我不利?它不会以'/>结尾“ – SpYk3HH 2013-05-06 18:36:35