javascript - 更改标题样式 jquery - css

标签 javascript jquery css title

我正在尝试更改所有链接的标题样式,但是我刚刚找到了如何为 <a> 执行此操作链接不适用于表单,<td>和图像标题更近。任何人都可以帮助我使用 jquery 来获取它..这是我的代码:

    <!DOCTYPE html>
<html>
    <head>
        <title>Anchor Title Demo</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
        <script>

            $(document).ready(function() {

                $('body').append('<div id="anchorTitle" class="anchorTitle"></div>');

                $('a[title!=""]').each(function() {

                    var a = $(this);

                    a.hover(
                        function() {
                            showAnchorTitle(a, a.data('title')); 
                        }, 
                        function() { 
                            hideAnchorTitle();
                        }
                    )
                    .data('title', a.attr('title'))
                    .removeAttr('title');

                });



            });

            function showAnchorTitle(element, text) {

                var offset = element.offset();

                $('#anchorTitle')
                .css({ 
                    'top'  : (offset.top + element.outerHeight() + 4) + 'px',
                    'left' : offset.left + 'px'
                })
                .html(text)
                .show();

            }

            function hideAnchorTitle() {
                $('#anchorTitle').hide();
            }

        </script>

        <style>
            body {
                background-color: white;
                font-family: Helvetica, Arial, sans-serif;
                font-size: 14px;
            }
            /* title style
             */
            .anchorTitle {
                /* border radius */
                -moz-border-radius: 8px;
                -webkit-border-radius: 8px;
                border-radius: 8px;
                /* box shadow */
                -moz-box-shadow: 2px 2px 3px #e6e6e6;
                -webkit-box-shadow: 2px 2px 3px #e6e6e6;
                box-shadow: 2px 2px 3px #e6e6e6;
                /* other settings */
                background-color: #fff;
                border: solid 3px #d6d6d6;
                color: #333;
                display: none;
                font-family: Helvetica, Arial, sans-serif;
                font-size: 11px;
                line-height: 1.3;
                max-width: 200px;
                padding: 5px 7px;
                position: absolute;
            }
            * html #anchorTitle {
                /* IE6 does not support max-width, so set a specific width instead */
                width: 200px;
            }
        </style>
    </head>
    <body>


        <p>
            <a href="#" title="The title will appear in an box when the mouse is over the link">Hover over me</a>
        </p>
        <div>
            <input type="text"  title="The title will appear in an box when the mouse is over the link" name="styleSwitcher" placeholder="Hover over me" /><p></p><p></p>
             <dt title="The title will appear in an box when the mouse is over the link">Hover over me </dt>
        </div>

    </body>
</html>

演示: http://jsfiddle.net/NVENA/2/

最佳答案

要使代码对具有非空 title 属性的所有元素进行更改,请从

中删除元素名称 a
            $('a[title!=""]').each(function() {

成功

            $('[title!=""]').each(function() {

关于javascript - 更改标题样式 jquery - css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12015591/

相关文章:

javascript - 在 HTML 的有序列表中为大数字添加逗号

JavaScript/Node.js : function returning another function based on parameters

javascript - 为什么这两个 JavaScript 函数不等价?

google-chrome - 转换样式 :preserve-3d and opacity in latest google chrome

html - 如何获得 tr :nth-of-type(odd) for entire table not group (thead, tbody)?

javascript - jquery .click 事件不适用于 chrome 扩展中的图像

javascript - 根据溢出隐藏和显示一些div

javascript - jQuery val 未定义?

javascript - Jquery 查找和每个选择器

javascript - 无法更改文本框颜色?