elliott.david 2014-02-21 18:17 采纳率: 25%
浏览 27

ajax yii jquery addclass

I had the response on my previous post to select a specific class in a page. (using this)

I'm using Yii framework and the use of this does not work

<div class="ajaxlink">
        <?php           

            echo CHtml::ajaxLink(
              'Test request',         
              array($url_replace),
              array(
                   'update'=>'.loading' ,
                   'beforeSend' => 'function() {  
                       $(this).removeClass("loading");         
                       $(this).addClass("loading");
                   }',
               )
            );
        ?>
</div>

in short when I click the ajaxlink , I call the action view of my controller which renderPartial a view with ClistView.

I dont know how to solve the problem, with the code above, nothing happens.

If I replace this with Ajaxlink, the class is added to all classes of the page.

To be clear, when the page is rendered, I have a list of post with related links.

<div class="content">

   blabla blabla

   Link
</div>
<div class="content">
   blabla blabla  2
   Link
</div>

when I click to the first link , I want to add a class below this link only

Thank you in advance for your help

  • 写回答

1条回答 默认 最新

  • 衫裤跑路 2014-02-21 22:47
    关注

    If I understand you correctly.

    Jquery's next() http://api.jquery.com/next/. Taken from JQuery

    <ul>
    <li>list item 1</li>
    <li>list item 2</li>
    <li class="third-item">list item 3</li>
    <li>list item 4</li>
    <li>list item 5</li>
    </ul>
    
    $( "li.third-item" ).next().css( "background-color", "red" );
    

    You could replace .css() with .addClass() and add a click()

    So something like this:

    $('a').click(function() {
    $(this).next('.content').addClass('myClass');
    });
    

    Again, if I understand you correctly. This will add a class to the next .content div after the <a> is clicked.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿