如何在 JavaScript 中的表单中每三个字符添加一个空格并具有替换功能?
如何在 JavaScript 中的表单中每三个字符添加一个空格并具有替换功能?我已经看到了这个问题,但我对此仍然不清楚并且是新的,并且我不确定代码将进入脚本的何处。这是我到目前为止所拥有的。请具体说明。
<script type="text/javascript">
function var myfunction()
{
}
</script>
</head>
<body>
<FORM ACTION="rules.html" NAME="form">
<INPUT TYPE=TEXT NAME="inp" SIZE=40 onkeyup="this.value=this.value.replace('t','A').replace('a','U')">
</FORM>
</script>
How do I add a space every three characters in a form in JavaScript and have a replace function? I've seen the question, but I'm still unclear and new at this and I'm not sure where the code would go into the script. This is what I have so far. Please be specific.
<script type="text/javascript">
function var myfunction()
{
}
</script>
</head>
<body>
<FORM ACTION="rules.html" NAME="form">
<INPUT TYPE=TEXT NAME="inp" SIZE=40 onkeyup="this.value=this.value.replace('t','A').replace('a','U')">
</FORM>
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,这就像你试图进入 RNA 并让它在进入时自动分裂成三联体。但即使这不是您正在做的,这也应该能满足您的需求。
首先,删除表单下方多余的结束
标记。
然后,将表单中的
input
替换为以下内容:并在
myfunction
函数中使用以下内容:当然,如果您将 javascript 从标记中提取出来,那么这一切都会变得更清晰,并且稍微清理一下你的 HTML,但这应该能让你继续前进。
It looks to me like your trying to enter in RNA and have it automatically split out into triplets on entry. But even if that's not what you're doing, this should get you what you need.
First, remove the extra closing
</script>
tag you have below your form.Then, replace the
input
in your form with the following:and in the
myfunction
function use this:Granted this could all be cleaner if you pulled your javascript out of your markup and cleaned up your HTML a little, but this should get you going.