0

我正在使用 Zend Framework 并使用 Zend_Db 从数据库中检索行。HTML如下。目的是在单击时切换幻灯片列中的“是/否”文本。ajax 调用有效并返回正确的结果。但是,我无法选择单元格并更改文本。

<table class="table table-bordered table-striped">
            <thead>
            <tr>

                <th>ID</th>
                <th>title</th>
                <th>Caption</th>
                <th>Image</th>
                <th></th>
                <th></th>
                <th>Slideshow</th>
            </tr>
            </thead>
            <tbody>
                <?php
                foreach($this->sections as $section){
                    if($section['slide']==0){ $slideText='No';  }
                    if($section['slide']==1){ $slideText='Yes';  }
                    ?>
                <tr>

                    <td>
                        <span class="badge"><?php echo $section['id']; ?></span>
                    </td>
                    <td>
                        <?php echo $section['caption']; ?>
                    </td>
                    <td>
                        <?php echo $section['comment']; ?>
                    </td>
                    <td>
                        <img src="/images/uploads/<?php echo $section['image_url']; ?>" width="180" height="100">
                    </td>
                    <td><a href="<?php echo $this->url(array('id'=>$section['id'],'sid'=>$this->id, 'type'=>'edit'),'admin-edit')  ?>">Edit</a></td>
                    <td><a href="<?php echo $this->url(array('id'=>$section['id'],'sid'=>$this->id,'type'=>'delete'),'admin-edit')  ?>">Delete</a></td>
                    <td class="imgajax"><a href="<?php echo $this->url(array('id'=>$section['id'],'type'=>'update'),'ajax-admin',true,true)  ?>" class="slide"><?php echo $slideText; ?></a></td>
                </tr>
                    <?php }?>

            </tbody>
        </table>
        <?php } ?>

javascripts如下;

$(".imgajax a").click(function(event){
        event.preventDefault();
        var url = $(this).url();
        id = url.segment(4);

        $.ajax({
            type: 'GET',
            url:"/admin/ajax",
            data:"id="+id,
            success: function(data) {
                console.log(data);

                if(data==1){
                    $('.slide').text('Yes');
                }
                if(data==0)
                {
                    $('.slide').text('No');
                }
            }
        });

    });
4

1 回答 1

0

你应该使用

$('.slide').html('Yes');

代替

$('.slide').text('Yes');
于 2012-08-21T08:59:36.280 回答