[英]JS/JQuery: Dynamically add “pattern” and “title” attribute to form input
[英]How to add pattern and title in input
大家好,我有以下代码:
<form>
<input type="text" id="FormField_6_input" name="CompanyName"/>
<button id="ContinueButton_6">Continue</button>
</form>
<script>
let companyNameField = document.getElementById('FormField_6_input');
companyNameField.setAttribute("pattern", "/[2-9]{1}\d{3}/");
companyNameField.setAttribute("title", "invalid input");
</script>
我想将模式和标题属性添加到我的输入中,但它不起作用请帮我解决这个问题。
我编辑了您的代码,请查看。
let companyNameField = document.getElementById('FormField_6_input'); companyNameField.setAttribute("pattern", "[2-9]\\d{3}" ); companyNameField.setAttribute("title", "invalid input");
<form> <input type="text" id="FormField_6_input" name="CompanyName"/> <button id="ContinueButton_6">Continue</button> </form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.