php - 如何在图像标签中放置标志状态

标签 php javascript css image

我需要在下面的代码中使用像 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');
});

最佳答案

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

我假设您在代码中使用 jQuery。

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

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

关于php - 如何在图像标签中放置标志状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9938264/

相关文章:

php - 在查询参数后从 URL 中删除 index.php 而不使用 .htaccess

JavaScript数组中的第二大元素代码错误

javascript - 谷歌说代码无效,我的错误在哪里?

javascript - 将选定的记录加载到模态窗口

php - 如何获取完整的 URL 以在 Laravel 中显示

php - $_GET 在 php 中不返回任何值

PHP 将一个数组附加到另​​一个数组(不是 array_push 或 +)

类似 Jquery Finder 的菜单

html - 包含数字的 Ol strip 化

html - 在 bootstrap 中居中对齐 div 内容