我想在我的fbml粉丝页面中,在表单下方插入此javascript代码。 但它不起作用(在一个简单的html页面中效果很好)......
<script type="text/javascript">
var months=new Array{"January","February","March","April","May","June","July","August","September","October","November","December"};
var message='Date out of planning range';
function init {var d=new Date();var y=d.getFullYear();var lm=document.getElementById('AVP_list_months');var ld=document.getElementById('AVP_list_days');var ln=document.getElementById('AVP_list_nights'); for(i=0;i<12;i++){var m=(d.getMonth()+i)%12;if(m==0&&i!=0)y++;appendOption(lm,months[m]+' '+y,y+'-'+(m+1));}for(i=1;i<=31;i++){appendOption(ld,i,i);if(i<31)appendOption(ln,i,i);}ld.selectedIndex=d.getDate()-1;setDays();}
function setDays(){var ld=document.getElementById('AVP_list_days');var lm=document.getElementById('AVP_list_months');var ym=lm.options[lm.selectedIndex].value;var y=eval(ym.substring(0,4));var m=eval(ym.substring(5,ym.length));var d=getDaysInMonth(y,m);if(d>ld.length){for(i=ld.length;i<d;i++)appendOption(ld,i+1,i+1);}if(d<ld.length){if(ld.selectedIndex>d-1)ld.selectedIndex=d-1;ld.length=d;}}
function appendOption(l,t,v){var e=document.createElement('option');e.text=t;e.value=v;try{l.add(e,null);}catch(ex){l.add(e);}}
function getDaysInMonth(y,m){var days=[31,28,31,30,31,30,31,31,30,31,30,31];var d=days[m-1];if(d==28){if(isLeapYear(y))d=29;}return d/1;}
function isLeapYear(y){if(y%400==0||(y%4==0&&y%100!=0))return true;return false;}
function validate(){var lm=document.getElementById('AVP_list_months');var ld=document.getElementById('AVP_list_days');var ym=lm.options[lm.selectedIndex].value;var y=eval(ym.substring(0,4));var m=eval(ym.substring(5,ym.length));var d=new Date();var t=new Date(d.getFullYear(),d.getMonth(),d.getDate());d=new Date(y,m-1,eval(ld.options[ld.selectedIndex].value));if(d<t){alert(message);return false;}var ln=document.getElementById('AVP_list_nights');document.getElementById('AVP_arrivalDate').value = lm.options[lm.selectedIndex].value+'-'+ld.options[ld.selectedIndex].value;document.getElementById('AVP_nights').value = ln.options[ln.selectedIndex].value;document.getElementById('AVP').submit();}
init();
答案 0 :(得分:0)
据我所知,您正在使用FBJS不支持的eval
功能。