答案 0 :(得分:1)
问题是你在g>g
两次循环并在第二次运行时覆盖了原始值。
var $svg = jQuery(data).find('svg');
$('g>g').each(function() {
var $input = $( this );
var c = function () {
return $input.attr("name") //get the "name" attributes and store in var c
};
/*
$(this).append("<title/>"); //create <title> tag
// This part here is over-writing your previous title.
$('g>g>title').each(function() { //I am in <title> tag
$(this).text(c) //pass all "c" as text to each <title>
});
});
*/
// Use this instead to set the title on the current
// element.
$(this).attr("title", c); // correct way to set the title attribute
});