【问题标题】:Show a direct link of the window in textarea在 textarea 中显示窗口的直接链接
【发布时间】:2015-10-16 19:55:59
【问题描述】:

请帮帮我!对不起,我的措辞有些混乱!

我需要在 textarea 中显示窗口的直接链接。

例如:

我的链接:https://stackoverflow.com/123456.

使用:window.location.href

<textarea> ?/?/? window.location.href ?/?/? </textarea>

=> 结果如何显示=>

<textarea>https://stackoverflow.com/123456</textarea>

【问题讨论】:

    标签: javascript html hyperlink window textarea


    【解决方案1】:

    这对于 textarea 是不可能的,你需要一个 contenteditable div

    <div contenteditable="true"></div>
    

    【讨论】:

    • 它被称为文本区域是有原因的,amirite?
    • 如果我将“textarea”替换为“input”会怎么样?
    • @LêTùng 很高兴我能帮上忙。
    【解决方案2】:
    <!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>
    

    第二个是“奇怪”而不是“好”,因为您可以更改 URL 的文本,但是 A) 链接保持不变,并且 B) 您必须右键单击它才能浏览到它.也许您需要对事件进行更多控制才能获得您想要的可编辑链接。

    【讨论】:

      猜你喜欢
      • 2014-01-06
      • 2013-11-09
      • 1970-01-01
      • 1970-01-01
      • 2015-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      相关资源
      最近更新 更多