好的,我猜任何页面周围都有大量的标题(和 alt)属性。老实说,到目前为止,我一直在用 SweetTitles(js 库)修饰它们,但由于我的页面支持 jQuery,我想用 jQuery 让它更快、更稳固。
关于将什么写入 jQuery 和 .css 以在悬停时调用标题(和 alt)属性的任何建议 - 无需向这些属性添加 ID?
注意:抱歉,我指的是链接和图像中的那些标题和替代属性...比如
<img src="something.jpg **alt**="This is image"> or <a href="something.php" **title**="Go to this page">
标题=
最佳答案
编辑:在您的情况下,您可能需要如下,
img[alt] { /* set style for all img tag with alt attr */ }
a[title] { /* set style for all link tag with title attr */ }
同样的逻辑适用于 jQuery:
$('img[alt]') //will return all img tags with alt attribute
$('a[title]') //will return all link tags with title attribute
您需要阅读 jQuery 和 css 中的属性选择器
。请参阅以下链接,
我创建了一个简单的示例来向您展示如何在 css 和 jQuery 中使用属性选择器。参见 DEMO
HTML:
<div title="test" ></div>
<div title="test2"></div>
<div title="test" ></div>
<div title="test2"></div>
<div title="test" ></div>
<div title="test2"></div>
<div title="test" ></div>
<div title="test2"></div>
CSS:
div { width: 20px; height: 10px; margin: 10px; display: inline-block; }
div[title=test] { border: 1px solid red; }
div[title=test2] { border: 1px solid blue; }
JS:
$('div[title=test]').css ('background-color', 'red');
$('div[title=test2]').css ('background-color', 'blue');
希望对你有帮助。
关于jquery - 通过 jQuery 调用所有标题(可能还有 alt)属性 - 并在悬停时对它们进行 CSS 处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9813606/