[英]Use Class Instead of ID (Get element by CLASS not ID)
我正在使用原型工具提示,它使用ID作為元素。 我在頁面中有更多工具提示,因此它不允許我在頁面中使用相同的ID。 有沒有辦法使用CLASS作為元素而不是ID? 這就是我所擁有的。
<div style="margin-right: 2px" id="tooltip_bio" class="">Learn More</div>
<script type="text/javascript" language="javascript">
new Tip('tooltip_bio', "Tooltip Content", {
title: "Bio",
closeButton: true,
showOn: 'click',
hideOn: { element: 'closeButton', event: 'click'},
stem: 'bottomMiddle',
hook: { target: 'topMiddle', tip: 'bottomMiddle' },
offset: { x: 0, y: -2 },
width: '300px'
});
</script>
我對prototypejs
不是很熟悉,但是如果它需要一個ID,只需將你的ID放在一個數組中,然后迭代。
;["id_1", "id_2", "id_3"].each(function(id, i) {
new Tip(id, "Tooltip Content", {
title: "Bio",
closeButton: true,
showOn: 'click',
hideOn: { element: 'closeButton', event: 'click'},
stem: 'bottomMiddle',
hook: { target: 'topMiddle', tip: 'bottomMiddle' },
offset: { x: 0, y: -2 },
width: '300px'
});
});
從原型文檔中你可以做到這樣的事情。
document.observe('dom:loaded', function() {
$$('a[rel]').each(function(element) {
new Tip(element, element.rel,{
title: "Bio",
closeButton: true,
showOn: 'click',
hideOn: { element: 'closeButton', event: 'click'},
stem: 'bottomMiddle',
hook: { target: 'topMiddle', tip: 'bottomMiddle' },
offset: { x: 0, y: -2 },
width: '300px'
});
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.