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>
您不關閉您的標籤。同樣,'$('input [type = checkbox]')。removeClass('ui-helper-hidden-accessible');' – PSL 2013-05-05 05:26:33
哪個輸入元素? – pouya 2013-05-05 05:30:26
PSL 2013-05-05 05:30:52