如果輸入字段具有必需屬性,是否可以在標籤元素中添加<span class="required">*</span>
?如何在標籤中添加span.required元素,如果輸入需要屬性?
HTML:
<div class="form-group">
<label class="col-sm-4 control-label" for="customer_phone">Email:</label><p></p>
<div class="col-sm-8">
<input type="text" id="b_customer_email" class="form-control" size="40" value="<?php echo get_user_meta (get_current_user_id(),'b_customer_email',true);?>" name="b_customer_email" required>
</div>
</div>`
而且我已經試過這個jQuery:
$(document).ready(function(){
$("input").has("[required]")function() {
$(".control-label").after("<span class='required'>*</span>");
};
});
span元素標籤元素後不加。
我應該添加到腳本中才能使其工作?
我已經downvoted甚至沒有試圖檢查控制檯的明顯錯誤。 –
夠公平的。 jQuery語法關閉並且有一廂情願的想法 – mplungjan
[.has()](http://api.jquery.com/has/)尋找匹配選擇器的後代元素 - 在你的情況下,重新尋找。你應該使用屬性選擇器'$(「input [required]」)' –