私はいくつかの奇妙な動作を見つけました.誰かがここで助けてくれるかどうか疑問に思っていました.
addAttribute メソッドを継承する XhtmlTextWriter クラスを使用してフォームを作成しています。input
素敵な (HTML5) プレースホルダー属性を必要とするタグを作成しています。このaddAttribute
メソッドには、属性名と値の 2 つのパラメーターがあります。属性名は、HtmlTextWriteAttribute
列挙型から選択するか、文字列として手動で入力できます。列挙型では「プレースホルダー」を使用できないため、次のコードを使用しました。
StringWriter sw = new StringWriter();
XhtmlTextWriter html = new XhtmlTextWriter(sw);
html.AddAttribute(HtmlTextWriterAttribute.Type, "text");
html.AddAttribute(HtmlTextWriterAttribute.Name, "firstname");
html.AddAttribute("placeholder", "First Name");
html.AddAttribute("maxlength", "25");
html.RenderBeginTag(HtmlTextWriterTag.Input);
html.RenderEndTag();//input
return sw.ToString();
これにより、指定された要素と属性が適切に作成されます...プレースホルダーを除く:
<input type="text" name="firstname" maxlength="25"></input>
私のプレースホルダーがどこにあるか知っている人はいますか? ( でわかるようにmaxlength
、属性名に文字列を使用すると機能します...)
注: これは機能しますが、あまりきれいではありません。
html.WriteBeginTag("input");
html.WriteAttribute("type", "text");
html.WriteAttribute("placeholder", "First Name");
html.Write(HtmlTextWriter.SelfClosingTagEnd);
// 更新:required
属性に関する同じ問題... HTML5 固有のものでしょうか?