例如当前页面为:http://www.postcha.com/tangshi/ts_283.html想在这个页面加一个按钮<a id="down_a" href="" target="_blank">下载</a>,点击按钮转向http://www.postcha.com/down/ts_283.html并在新页面打开
其中的href要怎么写?,想用js实现。
其中的href要怎么写?,想用js实现。
调试欢乐多
<a id="down_a" href="" onclick="link()" target="_blank">下载</a><script>
function link(){
document.getElementById("down_a").href="http://www.postcha.com/down/ts_283.html";
}
</script>
我的想法是把这个地址http://www.postcha.com/down/ts_283.html、http://www.postcha.com/tangshi/ts_283.html拆分成三部份,前面的http://www.postcha.com/为一部份,中间的down/和tangshi/为一部份,后面的ts_283.html为一部份,这样写在一个JS文件里,是不是可以方便一点?
其实只有中间的部份发生了变化,前面都是一样的。
document.getElementById(id).href="http://www.postcha.com/"+channel+"/"+leaf;
}<a id="down_a" href="javaSrcript:void(0)" onclick="link('down_a','down','s_283.html');" target="_blank">下载</a>