简体   繁体   English

在Javascript中“@”之前拆分文本框文本值

[英]Split text box text value in before “@” in Javascript

Here i have txtemailid and txtlogin(read only) what i type in txtemailid before @ text it will directly go to txtlogin text box when i will happen means when i type something in email text box and next click to mouse without entering the user. 在这里,我有txtemailid和txtlogin(只读)我在txtemailid之前键入的内容@ text将直接转到txtlogin文本框,当我将要发生意味着当我在电子邮件文本框中键入内容并在下一次单击鼠标而不进入用户时。 how can i do this java and i take code in java script it's not working 我怎么能做这个java,我在java脚本中采取代码它不起作用

Thank you 谢谢

It is better you use keyboard event to make changes on each time a key is pressed.I am doing using onkeyup .I prefer document.getElementById() rather than document.form because it can accurately retrieve it, every time, without caring about what happens to the document in the meantime.You can use either of the two. 每次按下一个键时,最好使用键盘事件进行更改。我正在使用onkeyup 。我更喜欢document.getElementById()而不是document.form因为它可以每次都准确地检索它,而不用关心什么同时发生在文档中。您可以使用两者中的任何一个。

JSFIDDLE 的jsfiddle

Here is the code: 这是代码:

 function myFunction() { var text1 = document.getElementById("txtEmailId").value; var result = text1.split("@"); document.getElementById("txtLoginname").value = result[0]; } 
 <form> Enter Email: <input type="text" id="txtEmailId" onkeyup="myFunction()" /><br/><br/> Login Name: <input type="text" id="txtLoginname" /><br/><br/> </form> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM