繁体   English   中英

动态创建锚标记

[英]Dynamically create anchor tag

我有一个名为“ txt_contact”的文本框。 用户填写他的联系人,包括他的电子邮件ID,例如:

Contact:   Reggie Frederick, Email: regtnt@rediffmail.com; Mob: +91 984 807 7749 

我将此信息保存在数据库中。 但是我想将“ regtnt@rediffmail.com”作为定位标记,并且单击它时应将其重定向到rediffmail.com。 如何做到这一点?

这是我已经尝试过的。

    string cont = txt_contact.Text;
    Regex regx1 = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase);
    MatchCollection matches = regx1.Matches(cont);
    foreach (Match match in matches)
        {
            cont = cont.Replace(match.Value, "<a class='abc' href='" + match.Value + "'>" + match.Value + "</a>");
        }

注意:用户可以在文本框中填写任何电子邮件帐户(gmail,yahoo等)

这对我有帮助:

显示数据时,我正在为电子邮件编写正则表达式。

 $(document).ready(function () { 
        var regEx = /(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)/;
        var contact = $("span[id*=lblContact]")
        $(contact).filter(function () {
            return $(this).html().match(regEx);
        }).each(function () {
            $(this).html($(this).html().replace(regEx, "<a style=color:blue href=\"mailto:$1\">$1</a>"));
        });
    })

暂无
暂无

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

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