【发布时间】:2017-10-29 05:05:24
【问题描述】:
所以我有以下代码:
// the loop
$countId = 0;
$dateOnce = '';
foreach ($postDates as $post):
if (substr($post->post_date, 0, 7) != $dateOnce) {
echo'
<div class="checkbox">
<label for="filterByPostDate-' . $countId . '">
<input type="checkbox" id="filterByPostDate-' . substr($post->post_date, 0, 7) . '" class="postDateFilters postDateFilterCb-' . $countId . '" name="filterByPostDate-' . $countId . '" value="' . substr($post->post_date, 0, 7) . '" '; if (isset($_SESSION["filterByPostDate"])) { $key = array_search(substr($post->post_date, 0, 7), $_SESSION["filterByPostDate"]); } else { $key = false; } if($key !== false) { echo 'checked'; } echo ' />
' . date('M, Y', strtotime($post->date_part)) . '
</label>
</div>
';
}
$dateOnce = substr($post->post_date, 0, 7);
$countId++;
endforeach;
// END the loop
为 wordpress 前端输出复选框和标签。 但是当我点击每个复选框的标签时,复选框并没有被选中。
这是一个js fiddle,它显示了问题。
为帮助干杯。
【问题讨论】:
-
标签“for”和复选框“id”必须相同。 working example
标签: javascript jquery wordpress twitter-bootstrap checkbox