2013-05-05 264 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