更新时间:2023-02-26 11:30:03
我自己的方法是:
$('a[accesskey]').each( //selects only those a elements with an accesskey attribute
function(){
var aKey = $(this).attr('accesskey'); // finds the accesskey value of the current a
var text = $(this).text(); // finds the text of the current a
var newHTML = text.replace(aKey,'<span class="access">' + aKey + '</span>');
// creates the new html having wrapped the accesskey character with a span
$(this).html(newHTML); // sets the new html of the current link with the above newHTML variable
});
参考文献:
attr()
.replace()
html()