FBML 表单和 JS

发布于 2024-10-15 01:17:03 字数 2238 浏览 4 评论 0原文

我想将此 javascript 代码插入到我的 fbml 粉丝页面中,就在表单下方。 但它不起作用(在简单的 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();

I would like to insert this javascript code in my fbml fan page, just below the form.
But it doesn't work (works well in a simple html page)...

<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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ζ澈沫 2024-10-22 01:17:03

据我所知,您正在使用 FBJS 不支持的 eval 函数。

You are using eval function which isn't supported in FBJS as far as I know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文