ID Shold动态变化

时间:2017-04-14 07:38:02

标签: jquery cakephp

我正在使用cakephp 2.9。我想动态地给ID。 ID应根据字母更改。

$alphas = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');    
<script>
    $(document).ready(function() {
        $('#lettera').click(function() {
            var a = $('#lettera').text();/* alert(a); */
        });
    });
</script>
<section>
    <div class="container">
        <div class="row">
            <ul class="list-inline">
                <li>
                    <?php
                        foreach($alphas as $letter){
                            echo ($this->Html->tag('a', $letter, ['id' => 'letter'.$letter]));
                        }
                        echo $this->Html->para('bid_val', '');
                    ?>
                <li>
            </ul>
        </div>
    </div>
</section>

1 个答案:

答案 0 :(得分:0)

只需在每个字母中添加课程,然后使用获取点击的字母值。

$(document).ready(function() {
    $('.letter').click(function() {
        var character = $(this).text();
    });
});


foreach($alphas as $letter){
    echo ($this->Html->tag('a', $letter, ['id' => 'letter'.$letter, 'class' => 'letter']));
}