2012-07-02 2 views
-1

앵커 태그에 입력 할 URL을 입력하고 있습니다. 자바 스크립트에서 URL을 앵커 태그로 만드시겠습니까?

내가 솔루션을 찾고 있어요이

<a href="http://www.google.com">http://www.google.com</a> 
+0

처럼이 URL을 넣을 URL이

var url = "http://www.google.com"; 

가정하자. 나는 이것을하지 않았다. 그게 내가 왜 여기에 충격을 주 었는지. – Vicky

답변

3

document.createElement

var a = document.createElement('a'); 
a.href = "http://google.com"; 
a.textContent = a.href 
+0

'.innerHTML ='대신'.textContent' 또는'.innerText' 또는'.appendChild (document.createTextNode (...))'를 사용하십시오. –

+0

@RobW IE와 FF가 textContent와 innerText를 지원하지 않았다고 생각했기 때문에 @RobW가 있었지만 그 이상은 아닙니다. 감사. – sachleen

+0

오래된 텍스트는'textContent'를 지원합니다. 호환성을 위해서'[document.textContent === null? 'textContent': 'innerText']'([document.textContent'는 지원 될 때 null이어야합니다.] (https://developer.mozilla.org/en/DOM/Node.textContent#Description)). –

관련 문제