【问题标题】:HTML input tag: how to have lots of text for title attribute?HTML 输入标签:如何为标题属性添加大量文本?
【发布时间】:2020-01-31 05:14:53
【问题描述】:

问题

在 HTML 输入类型 button 中为 title 属性添加大量文本的最佳方法是什么?

目前我实际上只有很多文本,但这会导致 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 属性使用大量文本?因为我试图在工具提示中提供有关按钮用途的说明。我的网页很拥挤,我不想将文本列为按钮外部的段落。我对其他想法持开放态度。

来源:https://stackoverflow.com/a/2238299/11163122

【问题讨论】:

  • 我认为这是一个编码/编程问题,更多的是用户体验问题。因此,这可能值得问User Experience。

标签: html html-input html-title


【解决方案1】:

因此,这可以使用 Javascript 来完成,如下所示:

var inputDoSomething = document.getElementById('DoSomething');
inputDoSomething.setAttribute('title', 'This a shadow of the amount of text one can put as the title.');
&lt;input id="DoSomething" type="button" name="DoSomething" value="Do Something"&gt;

或者通过你的后端文件(我假设是 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">

【讨论】:

  • 谢谢@EGC,这对 Javascript 来说是个好主意!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-28
  • 2014-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多