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.
私は特に怠け者で、必要なすべてのフォーム フィールドのラベルに小さなアスタリスクを jQuery に追加させようとしています。
MVC は、すべての必須フォーム フィールドに「data-val-required」属性を追加します。$("form").find("[data-val-required]") を使用して一致するすべての要素を見つけることができることはわかっていますが、そのコレクションをループして、一致する名前のラベルに * を追加する方法がわかりません.
ありがとう!
jQuery:
$("[data-val-required]").each(function() { $("label[for=" + this.id + "]").addClass("required") });
CSS:
label.required::after{ content: " *" }
フィドル: http://jsfiddle.net/rxw8k/3/