【问题标题】:How to put the flag status in the image tag如何将标志状态放在图像标签中
【发布时间】:2014-04-09 06:25:50
【问题描述】:

我需要在下面的代码中使用像 imagestatus =1 这样的标志来检查 img 标签中图像的状态

 echo '<a href="#" class="swap-menu"><img id="menu_image"  src="images/collapsed.gif" hspace = "2"/>'.$B->getAttribute('TITLE').'</a>'; 

这是js文件

$('.swap-menu').bind('click', function (event) {
    $('.sub-menu').find("+ ul").slideUp(1);
    $(this).find("+ ul").slideToggle("fast");
    $(this).find("img").attr('src', 'images/expanded.gif');
});

【问题讨论】:

  • 在 js 文件中看到你的代码似乎你正在使用 jQuery。所以要更新img标签的src,你可以使用jQuery切换功能。 api.jquery.com/toggle

标签: php javascript css image


【解决方案1】:

当您替换图像 src 时,我会为图像添加一个类。

我假设您使用的是 jQuery,来自您的代码。

http://api.jquery.com/addClass/

然后你可以使用 hasClass 方法。见Determine if an element has a CSS class with jQuery

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-17
    • 1970-01-01
    • 2022-12-17
    • 1970-01-01
    • 2011-12-24
    • 2011-03-25
    • 2017-12-16
    • 1970-01-01
    相关资源
    最近更新 更多