2015-10-16 22 views

回答

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> 

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

+0

感谢您的帮助:) – LeTung

2

这是不可能与一个文本,你需要一个contenteditablediv

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

由于某种原因,amirite被称为* text *区域? –

+0

@SterlingArcher你是对的。 :P – Script47

+0

如果我将“textarea”替换为“input”,它将会如何? – LeTung