public static MvcHtmlString TextBoxForWithTooltip<Tmodel, TProperty>(this HtmlHelper<Tmodel> htmlHelper, Expression<Func<Tmodel, TProperty>> expression, object htmlAttributes = null, string tooltip = "")
{
var metaData = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
IDictionary<string, object> attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
if (!string.IsNullOrEmpty(metaData.Description))
{
attributes.Add("title", metaData.Description);
}
if (!string.IsNullOrWhiteSpace(tooltip))
{
attributes.Add("data-tooltip", tooltip);
}
if (attributes.ContainsKey("style"))
{
var val = attributes["style"];
attributes["style"] = val + ";border-radius: 6px;";
}
else
{
attributes.Add("style", "border-radius: 6px;");
}
return htmlHelper.TextBoxFor(expression, attributes);
}
そして、私は[こちら]からもらったCSS、[1]。これは、データツールチップをボタンまたは "a"または "li"要素に割り当てるときに効果的です。しかし、入力やTextBoxForではありません。私はページソースの中にdata-tooltip属性を見ていますが、明らかにCSSを起動してツールチップを表示しません。なぜ誰かがアイデアを持っていますか?私は、ツールヒントを得るためにDIVの中にHTMLを埋め込ま
public static MvcHtmlString TextBoxForWithTooltip<Tmodel, TProperty>(this HtmlHelper<Tmodel> htmlHelper, Expression<Func<Tmodel, TProperty>> expression, object htmlAttributes = null, string tooltip = "")
{
IDictionary<string, object> attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
if (attributes.ContainsKey("style"))
{
var val = attributes["style"];
attributes["style"] = val + ";border-radius: 6px;";
}
else
{
attributes.Add("style", "border-radius: 6px;");
}
return MvcHtmlString.Create("<div data-tooltip='" + tooltip + "'>" + htmlHelper.TextBoxFor(expression, attributes) + "</div>");
}
:
は実際に私が何をしたか、このでした。バックこの質問は、回避策のカップルがあります頼まれた2013年には決定的な答えはありませんでしたけれども
CSSは '使用しているためである:Tを適用していない擬似要素after':before'と' Oなどinput'と '' textarea'などの要素を置き換え(*同じことが多くのためhttps://developer.mozilla.org/en-US/docs/Web/CSS/Replaced_elementを参照してくださいSELECT' '、img''のために行きます*) HTMLヘルパーがその内のテキストボックスにdivタグを返送するための –