简体   繁体   English

从电子邮件输入中仅复制域名

[英]Copy Only Domain Name from email input

I have an input field for email input and URl input field.我有一个用于电子邮件输入和 URl 输入字段的输入字段。 On double click i copy mail's value to url like this双击我将邮件的值复制到这样的网址

<script>
   function cp_mail() {
     document.getElementById("mail").value = document.getElementById("Url").value;
   }
 </script>  

Now i only want to copy domain name of email (from the "@" to the end) and insert on the begining of Url "www."现在我只想复制电子邮件的域名(从“@”到末尾)并在 Url 的开头插入“www”。 .Any Ideas ? 。有任何想法吗 ?

Simply try this试试这个

var domainName = emailId.split("@").pop();

or或者

var domainName = emailId.split("@")[1];

This will split the emailId by @ which will return the array of 2 items, one before @ and one after @ .这将通过分割EMAILID @这将返回的2项,一个前阵@和一个后@ Second item (or last item) is what you are looking for.第二项(或最后一项)是您要查找的内容。

Now compute the URL as现在将 URL 计算为

var url = "www." + domainName;

DEMO演示

 var emailId = "abc@domainname.com"; var domainName = emailId.split("@")[1]; var url = "www." + domainName; alert(url);

you can write like this你可以这样写

var email="test@domain.com";
var domainName = 'www.' + email.split('@')[1]

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

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