简体   繁体   English

jQuery 将文本框的文本转换为锚标记

[英]jQuery convert text from textbox to anchor tag

I am needing to put in a "secret" way of putting HTML into a textarea.我需要以一种“秘密”的方式将 HTML 放入文本区域。 Currently, I have a textarea and when a submit button is clicked, it posts the value to MySQL via ajax/php.目前,我有一个 textarea,当单击提交按钮时,它会通过 ajax/php 将值发布到 MySQL。

Instead of allowing HTML to be put into the textarea box (for security reasons), I am wanting a way to put something like #http://www.example.com/file.php# .而不是允许将 HTML 放入 textarea 框(出于安全原因),我想要一种方法来放置类似#http://www.example.com/file.php#东西。 Then on submit, it would convert anything inside the # symbol to an anchor tag然后在提交时,它会将 # 符号内的任何内容转换为锚标记

This - #http://www.example.com/file.php#这 - #http://www.example.com/file.php#

Would turn into this - <a href='http://www.example.com/file.php'>www.example.com</a>会变成这个 - <a href='http://www.example.com/file.php'>www.example.com</a>

 var A= $("p").html().replace("#","").replace("#",""); $("body").append( $("<a/>",{href:A,html:A.match(/(www?\\w*\\.)\\w+\\.\\w+/g)}))
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <p>#http://www.example.com/file.php#</p>

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

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