我正在编写一个自定义指令,它将为required
输入字段添加一个星号。这是我的链接功能,用评论解释:
// The DOM looks like this:
// <label id="label-1" for="example-1">Name:</label>
// <input id="example-1" type="text" acc-required>
function (scope, element, attrs) {
// element would be input node
// I included jQuery, so that I can use the selector as following.
var label = $("label[for='" + element.attr('id') + "']");
if (label) {
// @ add asterisk to the label of a required input field
var abbrElement = angular.element('<abbr title="required" class="required-marker"">*</abbr>');
label.append(compile(abbrElement)(scope));
}
}
根据输入的 id 属性选择标签是否有异味?