2

我在我的一种形式中使用 CListView。我在其中一列中使用了 CHtml::link。它的html是这样的

<a class="text-dark" value="31" href="javascript:void(0)" title="You received a new message">

然后点击这个链接我调用了一个javascript函数

跟随功能

 $('a.text-dark').click(function()
    {

        var id = $(this).attr('value');

        $.ajax({
                        type:'POST',
                        url:'<?php echo Yii::app()->createUrl('/mailbox/message/View') ?>/id/'+id,
                        success:function(data){ 

                                   },
                        error:function(data){ 
                                        alert('Your data has not been submitted..Please try again');
                                          }

          });
    });

我的主要问题是在第一页它完美无缺。函数被完美调用。但是每当我从分页中单击下一个按钮并单击此链接时。函数没有被调用。除了一页,任何页面都不会调用函数。什么是问题?

4

1 回答 1

0

问题是因为这是一个新元素,因此应该再次应用应用的功能,或者简单的解决方案

$(document).on('click', 'a.text-dark', function(){

   // do the job here
});

或向您的网格视图添加一个函数并在 ajax 更新后调用它

 'afterAjaxUpdate' => 'js:function(){ here do stuff }'
于 2015-01-12T10:57:17.603 回答