[英]How to remove certain warning text from input value only when user starts typing in the input field?
I have a value being php echoed in an input field after a form validation like so:我的值是 php 在表单验证后在输入字段中回显,如下所示:
x - Confirm valid surname
What code (Javascript only) is appropriate to use if I want to remove the matching text " - Confirm valid surname"
(this would be a warning message) when user starts typing inside the input field (ideally when changing to a valid surname)?如果我想在用户开始在输入字段中输入(理想情况下更改为有效姓氏时)删除匹配文本
" - Confirm valid surname"
(这将是一条警告消息),则适合使用什么代码(仅限 Javascript)?
Did your "input" be like this?你的“输入”是这样的吗?
<input value="<?php echo $errorMessage; ?>"/>
I advise to use the "placeholder" attribute,我建议使用“占位符”属性,
<input placeholder="<?php echo $errorMessage; ?>"/>
or if you want to keep using JS,或者如果你想继续使用 JS,
var inputBox = document.getElementById(INPUT_BOX_ID);
inputBox.oninput = function(){
inputBox.value = inputBox.value.replace(" - Confrim valid surname",""); // Simply remove the Error Text you've echoed
inputBox.oninput = null; // Delete the function so user can type something
}
// Its still not detecting the valid surname, but its removes the " - Confrim valid surname"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.