Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个按钮:
<button id="abc">abc</button>
如何设置此按钮的标题属性?
首先,获取对元素的引用:
var yourBtn = document.getElementById('abc');
然后,设置它的title属性:
title
yourBtn.title = 'Something';
你可以使用setAttribute方法
setAttribute
document.getElementById('abc').setAttribute("title", "Your title");