我如何在将来更改日期的链接目的地,因此链接是<a href="http://www.google.com">link</a>
,并且在31-01-2013我希望它是<a href="http://www.yahoo.com">link</a>
?
fixt:
<script type="text/javascript">
function callFunc() {
var compareDate = new Date(2014, 0, 31, 0, 0, 0, 0);
var curDate = new Date();
if (curDate.getTime() > compareDate.getTime()) {
return "http://www.amazon.com/gp/product/";
} else {
return "#";
}
}
document.write('<a href="' + callFunc() + '" target="_blank"><img src="/images/amazon.png" alt="amazon" title="amazon button" width="100%"/></a>');
</script>
答案 0 :(得分:1)
<script type="text/javascript">
function callFunc() {
var compareDate = new Date(2013, 0, 31, 0, 0, 0, 0);
alert("compareDate: " + compareDate.toString());
var curDate = new Date();
if (curDate.getTime() > compareDate.getTime()) {
return "http://www.yahoo.com";
} else {
return "http://www.google.com";
}
}
document.write('<a href="' + callFunc() + '">Link</a>');
</script>
答案 1 :(得分:0)
<a id = "myLink" href = "#">Link</a>
$('#myLink').on('click', function(){
//compare today's date and set a var url accordingly
$(location).attr('href', url);
});