请帮帮我!抱歉我的措辞有些令人困惑!
我需要在textarea中显示窗口的直接链接。
例如:
我的链接:https://stackoverflow.com/123456。
使用:window.location.href
<textarea> ?/?/? window.location.href ?/?/? </textarea>
=&GT;结果如何显示=&gt;
<textarea>https://stackoverflow.com/123456</textarea>
答案 0 :(得分:2)
对于textarea,这是不可能的,您需要contenteditable
div
。
<div contenteditable="true"></div>
答案 1 :(得分:1)
<!doctype html>
<title>editable URLs</title>
<textarea id=bad></textarea>
<p contenteditable=true><a id=odd></a></p>
<script>
(function() {
var bad = document.getElementById('bad'),
odd = document.getElementById('odd')
bad.textContent = window.location.href
odd.href = window.location.href
odd.textContent = window.location.href
})()
</script>
第二个是“奇怪”&#39;而不是“好”&#39;因为您可以更改URL的文本但是A)链接保持不变,并且B)您必须右键单击它才能浏览到它。也许您需要对事件进行更多控制,以获得您正在考虑的可编辑链接。