在textarea中直接显示window的link
Show a direct link of the window in textarea
请帮帮我!抱歉我的措辞有些混乱!
我需要在 textarea 中直接显示 window 的 link。
例如:
我的link:https://whosebug.com/123456。
使用:window.location.href
<textarea> ?/?/? window.location.href ?/?/? </textarea>
=> 结果如何显示=>
<textarea>https://whosebug.com/123456</textarea>
文本区域无法做到这一点,您需要 contenteditable
div
.
<div contenteditable="true"></div>
<!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>
第二个是 'odd' 而不是 'good',因为您可以更改 URL 的文本,但是 A) link 保持不变, B) 您必须右键单击它才能浏览到它。也许您需要对事件进行更多控制才能获得您想要的可编辑 link。
请帮帮我!抱歉我的措辞有些混乱!
我需要在 textarea 中直接显示 window 的 link。
例如:
我的link:https://whosebug.com/123456。
使用:window.location.href
<textarea> ?/?/? window.location.href ?/?/? </textarea>
=> 结果如何显示=>
<textarea>https://whosebug.com/123456</textarea>
文本区域无法做到这一点,您需要 contenteditable
div
.
<div contenteditable="true"></div>
<!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>
第二个是 'odd' 而不是 'good',因为您可以更改 URL 的文本,但是 A) link 保持不变, B) 您必须右键单击它才能浏览到它。也许您需要对事件进行更多控制才能获得您想要的可编辑 link。