问题
在HTML输入类型title
中为button
属性包含大量文本的最佳方法是什么?
目前,我实际上只有很多文本,但这会导致很长的HTML代码行。例如:
<input id="DoSomething" type="button" name="DoSomething" value="Do Something" title="This a shadow of the amount of text one can put as the title.">
我的用例
为什么title
属性使用大量文本?因为我试图在工具提示中提供有关按钮用途的说明。我的网页很拥挤,我不想在按钮外部将文本作为段落列出。我愿意接受其他想法。
答案 0 :(得分:1)
因此,这可以使用Javascript完成,如下所示:
var inputDoSomething = document.getElementById('DoSomething');
inputDoSomething.setAttribute('title', 'This a shadow of the amount of text one can put as the title.');
<input id="DoSomething" type="button" name="DoSomething" value="Do Something">
或通过您的后端文件(假设使用C#),如下所示:
C#
protected void Page_Load(object sender, EventArgs e)
{
DoSomething.Attributes.Add("title","This a shadow of the amount of text one can put as the title.");
}
.ASPX文件中的HTML
<input id="DoSomething" type="button" name="DoSomething" value="Do Something" runat="server">