내 페이지의 모든 링크를 동시에 특정 색상으로 변경할 수있는 방법이 있습니까? 예 :모든 문서 링크 색상 변경 자바 스크립트
아마 onclick 기능이 있다고 생각합니다. 지금까지 행운이 없습니다.
내 페이지의 모든 링크를 동시에 특정 색상으로 변경할 수있는 방법이 있습니까? 예 :모든 문서 링크 색상 변경 자바 스크립트
아마 onclick 기능이 있다고 생각합니다. 지금까지 행운이 없습니다.
어쩌면 동적으로 CSS를 만들 수 있습니다.
var styleElement = document.createElement("style");
styleElement.type = "text/css";
if (styleElement.styleSheet) {
styleElement.styleSheet.cssText = "a { color: red }";
} else {
styleElement.appendChild(document.createTextNode("a { color: red; }"));
}
document.getElementsByTagName("head")[0].appendChild(styleElement);
document.anchors는 배열을 반환하므로 루프를 통과해야합니다.
var anchors = document.anchors;
for(var i=0, m=anchors.length; i<m; i++){
anchors[i].style.color = "red";
}
은 이미 답했지만 어쨌든 잘 내 버전 :
<html>
<head>
<script type="text/javascript">
var ChangeColors = function() {
var elem = document.createElement('style');
elem.setAttribute("type", "text/css");
var style = document.createTextNode("A, A:hover, A:visited { color: red; }")
elem.appendChild(style);
document.getElementsByTagName("head")[0].appendChild(elem);
}
</script>
</head>
<body>
<a href="#">Some Link</a><br />
<a href="http://www.google.com">Some Other Link</a><br />
<input type="button" onclick="ChangeColors();"/>
<a href="#">Some Link 2</a><br />
<a href="#">Some Link 3</a><br />
</body>
</html>
: 왜이 게시물에 투표했는지 설명 할 수 있다면 매우 감사하겠습니다. 고맙습니다. – Vinzenz
1, 카우 벨하지 대답은 많은 감사합니다! 아래쪽 유권자에게 –