html分离JavaScript
- test.html
<html>
<head>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<a href="http://www.example/" class="popup">TEST</a>
</body>
</html>
- test.js
window.onload = prepareLinks;
function prepareLinks() {
var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
//if (links[i].getAttribute("class") == "popup") {
if (links[i].className == "popup") {
links[i].onclick = function() {
popUp(this.getAttribute("href"));
return false;
}
}
}
}
function popUp(winURL) {
window.open(winURL, "popup", "width=320,height=480");
}
更多推荐
html分离JavaScript
发布评论