[英]How can I add a red border to an input field along with the required attribute?
[英]Can I add the required attribute to an input field using css?
我的表單中有一個 recaptcha 小部件,我希望它成為強制性的。 因為我對 html 中的小部件沒有任何直接控制權,所以我想知道是否可以在它呈現后向其添加所需的屬性。
IE。 如果我添加以下 css
#recaptcha_response_field{background-color:#000000;}
它確實為 recaptcha 小部件文本字段着色。 同樣,如果有某種方法可以通過 css 為輸入字段設置 required="required" 屬性,我可以將其設為強制性。
以下是否適合您:
$(function() {
$("#recaptcha_response_field").attr('required','required');
});
如果我理解正確的話,這應該可以解決問題:
$(function() {
$("#recaptcha_response_field").css({background-color:#000000;});
});
沒有 jQuery:
document.onload = function() {
document.getElementById("recaptcha_response_field").style['background-color'] = '#000000';
};
我不是 100% 確定第二個,但我現在不能測試它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.