简体   繁体   English

仅当用户开始在输入字段中输入时,如何从输入值中删除某些警告文本?

[英]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.

相关问题 用户开始输入时,使突出显示的输入字段为“未突出显示” - Make highlighted input field 'unhighlighted' when user starts typing 用户开始输入输入时更改CSS - Change css when user starts typing in input 用户开始输入时如何自动打开弹出输入框 - How to automatically open a popup input box when user starts typing 用户开始输入时如何显示输入的最大长度? - How to display maxlength of input as user starts typing? 用户键入时从输入字段中删除字符(keyup) - remove character from input field while user is typing (keyup) 当用户在输入字段上键入时,如何替换某些字符? - How can I replace certain character when a user is typing on an input field? 即使没有选择输入,当用户开始打字时也会自动聚焦到输入 - Autofocus to input when user starts typing even not selecting the input 当用户在输入字段中输入数据时,如何从把手页面获取 jquery 中的输入文本值? - How to get the input text value in jquery from handlebar page when user enters data in input field? 当用户开始键入文本输入时,在单独的div中触发jQuery自定义事件 - Triggering a jQuery custom event in a separate div when user starts typing in a text input 当键入光标离开输入文本字段时如何触发功能? - How to trigger a function when the typing cursor leaves the input text field?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM