jQuery如何显示标题属性并附加到内部html

jQuery如何显示标题属性并附加到内部html,jquery,Jquery,抱歉,对jQuery来说是全新的。我想知道如何获取title属性并将其附加到a href标记的内部html中。我无法修改html源代码,但必须能够将标题文本附加到a href标记内文本的末尾。感谢社区的帮助 <script style="text/javascript"> $(document).ready(function() { $("#part4 > a").mouseover(function() {

抱歉,对jQuery来说是全新的。我想知道如何获取title属性并将其附加到a href标记的内部html中。我无法修改html源代码,但必须能够将标题文本附加到a href标记内文本的末尾。感谢社区的帮助

    <script style="text/javascript">
    $(document).ready(function()
    {
        $("#part4 > a").mouseover(function() {          
            $(this).next().html(("#part4 > a").attr("title")).toggle();
        });

        $("#part4 > a").mouseout(function() {
            $(this).next().html(("#part4 > a").attr("title")).toggle();
        });
    });
</script>
<div id="part4">
    <h2>4: Link and Title Attribute Demo</h2>

    <a href="#" id="linkTitle" title="This is text from the title attribute, wrapped in a span tag, placed here by jquery.">
    Hover over this text</a> 
</div>

$(文档).ready(函数()
{
$(“#part4>a”).mouseover(function(){
$(this.next().html((“#part4>a”).attr(“title”).toggle();
});
$(“#part4>a”).mouseout(函数(){
$(this.next().html((“#part4>a”).attr(“title”).toggle();
});
});
4:链接和标题属性演示

试试上面的。试试这个

$(document).ready(function()
{
    var text = $('#linkTitle').text();
    $("#part4 > a").mouseover(function() {                    
    $(this).html(text + $(this).attr('title')); 
   });
   $("#part4 > a").mouseout(function() {
     $(this).empty().append(text); 
   });
});
 $(document).ready(function() {
        $("#part4 > a").mouseover(function() {          
            var title = $(this).attr("title");
            var html = $(this).html();
            $(this).html(title);
            $(this).attr("title",html);
        }).mouseout(function() {          
            var title = $(this).attr("title");
            var html  = $(this).html();
            $(this).html(title);
            $(this).attr("title",html);
        });            
    });
试试这个

$(document).ready(function()
{
    var text = $('#linkTitle').text();
    $("#part4 > a").mouseover(function() {                    
    $(this).html(text + $(this).attr('title')); 
   });
   $("#part4 > a").mouseout(function() {
     $(this).empty().append(text); 
   });
});
 $(document).ready(function() {
        $("#part4 > a").mouseover(function() {          
            var title = $(this).attr("title");
            var html = $(this).html();
            $(this).html(title);
            $(this).attr("title",html);
        }).mouseout(function() {          
            var title = $(this).attr("title");
            var html  = $(this).html();
            $(this).html(title);
            $(this).attr("title",html);
        });            
    });

检查此示例。


<script style="text/javascript">
    $(document).ready(function()
    {
        default_text = $('#part4 > a').text();
        $('#part4 > a').hover(          
            function(){
                    $(this).html($(this).attr('title'));
            },
            function(){
                    $(this).html(default_text);
            }
        )
    });
</script>
$(文档).ready(函数() { 默认文本=$('#part4>a')。文本(); $(#part4>a')。悬停( 函数(){ $(this.html($(this.attr('title')); }, 函数(){ $(this).html(默认文本); } ) });
$(document).ready(function() {
        function hovertoggle(dis) {
          var title = dis.attr("title");
          var html  = dis.html();
          dis.html(title);
          dis.attr("title",html);
        }

        $("#part4 > a").mouseover(function() {          
            hovertoggle($(this)) ;
        }).mouseout(function() {  
            hovertoggle($(this));
        });            
    });
$(document).ready(function()
    {
        var linkTxt = ''
        $("#part4 > a").hover(function() {      
            linkTxt = $(this).text();
            $(this).append($(this).attr("title"));
        },function() {
            $(this).text(linkTxt);
        });
    });
<script style="text/javascript">
    $(document).ready(function()
    {
        default_text = $('#part4 > a').text();
        $('#part4 > a').hover(          
            function(){
                    $(this).html($(this).attr('title'));
            },
            function(){
                    $(this).html(default_text);
            }
        )
    });
</script>