【发布时间】:2015-04-18 05:30:09
【问题描述】:
这与这个问题有关(已解决):Previous Problem:Solved,只是为了给出问题的上下文。
我想要做的是将我从前面的代码中获得的链接应用到按钮元素中的 href 中。这是我到目前为止所得到的:
<script type="text/javascript">
var newestLink = "";
window.setTimeout(function(){
var newLink = $('.link:last').attr("href");
newestLink = newLink;
}, 1500);
window.setTimeout(function(){
alert(newestLink);
document.getElementById('#redButton').onClick = function() {
document.getElementById('#redButton').href=newestLink;
}
}, 3000);
</script>
alert 代码只是为了检查我的值是否正确。当我使用这段代码时,控制台返回错误Uncaught TypeError: Cannot set property 'onClick' of null (anonymous function)
我似乎无法理解代码哪里出错了。我正在关注this advise。
【问题讨论】:
-
去掉redButton上的#。
标签: javascript jquery