繁体   English   中英

单击时如何更改链接的颜色?

[英]how to change the color of link when clicked?

我想改变链接颜色onclick,链接是基于ajax,我尝试了很多,但没有成功我怎么能改变它,请求行动在这个页面上。

        <div class="topheading-right">
        <span>
            <?php echo $this->Manager->link('Archived Events', array('a'));?>
        </span>
        <?php echo $this->Manager->link('View All', array(''));?>
    </div>
</div>

<div id='events-event_list' class='dashboard-<?php echo __l($product_name);?>s'>
    <?php echo $this->requestAction(array('controller'=>'events', 'action'=>'view_event_list', $is_archive), array('return'));?>
</div>

我怎样才能做到这一点? 提前致谢

如果它是AJAX链接,则不能使用:visited伪选择器。

相反,使用:

 $('a').live('click',function(){this.style.css.color='red'})

或类似的东西

尝试

$('a[id^="link-"]').on('click',function(event){
   event.preventDefault();
   var Obj = $(this);
   Obj.css('color','red');
   var href = Obj.attr('href');
   //ajax call with url href
});

应该是这样的

 $('a').on('click',function(){
     $(this).css('color','red');
 });

在现代浏览器中(即使在IE10中)如果您将设置a:active伪类您将在没有JavaScript的情况下获得此结果:

a:active{ color: red; }

您还可以指定其他属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM