加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何将有效链接插入输入文本框?

发布时间:2020-12-13 17:48:08 所属栏目:PHP教程 来源:网络整理
导读:是否可以在输入文本框中插入活动链接? 我尝试使用 a标记在html的值内,但它不起作用. ?php $email = "a href="example@link.com"example@link.com /a"; ? input type="text" id="email" name="email" value="?php echo $email; ?" 它只返回没有超链接值的
是否可以在输入文本框中插入活动链接?

我尝试使用< a>标记在html的值内,但它不起作用.

<?php $email = "<a href="example@link.com">example@link.com </a>"; ?>   

<input type="text" id="email" name="email" value="<?php echo $email; ?>">

它只返回没有超链接值的文本.

解决方法

这里有几件事是错的……

>你没有逃脱你的报价.因此PHP无效.
>您正在尝试将HTML放在属性中,这也是无效的.

我可以看到在这里使用的唯一选择是应用了contenteditable =“true”的HTML元素.这使得元素(例如< div>)可以修改它的内容.

<?php $email = "<a href="example@link.com">example@link.com </a>"; ?>   
<div id="fake-email" contenteditable="true"><?php echo $email; ?></div>

如果您正在做表格,请参阅此related question.

编辑:

如果你正在尝试做一个表单,那么这就是一个例子:

document.getElementById("form").onsubmit = function(){
    document.getElementById("email").value =  
    document.getElementById("fake-email").innerText || document.getElementById("fake-email").textContent;
}

你的表格是:

<form action="..." method="..." id="form">
   <div id="fake-email" contenteditable="true"></div>
   <input type="hidden" id="email" name="email" />
</form>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读