抱歉,这对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>发布于 2013-12-10 13:12:38
尝尝这个
$(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);
});
});DEMO
发布于 2013-12-10 13:10:04
var text = $('#linkTitle').html();
$("#part4 > a").mouseover(function() {
$(this).html(text + $(this).attr('title'));
});
$("#part4 > a").mouseout(function() {
$(this).html(text);
});发布于 2013-12-10 13:12:25
$(this).html($("#selector").attr( "title" ));或
$(this).append($("#selector").attr( "title" ));试试上面的。
https://stackoverflow.com/questions/20486511
复制相似问题