gpt4 book ai didi

javascript - if javascript 中 .datepicker 属性的条件

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:19:03 26 4
gpt4 key购买 nike

我有一个日期选择器,我想要 defaultDate 属性,如果它满足我的条件。这是下面的代码,

 $(function () {
jQuery('#datepicker').datepicker({
<% if (parseInt(location.search.indexOf('did=')) >= 0) { %>
defaultDate: getDefaultDateVal(),
<% } %>
// defaultDate: parseInt(location.search.indexOf('did=')) >= 0 ? getDefaultDateVal() : new Date(),
inline: true,
maxDate: '+10D',
onLoad:function(){alert("hello");},
onSelect: function(date) {
//alert('Diet plan for ' + date);
var d = new Date("January 01, 1970 00:00:00");
var d2 = new Date(date);
d.setMonth(d.getMonth());
var theMonth;
theMonth = d.toString();
theMonth = theMonth.substr(4, 3);

d2.setMonth(d2.getMonth());
var theMonth2;
theMonth2 = d2.toString();
theMonth2 = theMonth2.substr(4, 3);

var firstDay = d.getDate();
var secondDay = d2.getDate();
var firstMonth = theMonth;
var secondMonth = theMonth2;
var firstYear = d.getFullYear();
var secondYear = d2.getFullYear();
var firstDate = new Date(firstDay + " " + firstMonth + " " + firstYear);
var secondDate = new Date(secondDay + " " + secondMonth + " " + secondYear);
var daysDiff = (secondDate.valueOf() - firstDate.valueOf());
daysDiff = Math.floor(Math.abs((((daysDiff / 1000) / 60) / 60) / 24));
//alert(daysDiff);


self.location.href = './Goal.aspx?did=' + daysDiff + '';
//filterGetMidHead(date);
//wait(500);

// alert(date);
var startdate = ((d2.getDate()).toString().length == 1) ? "0" + (d2.getDate()).toString() : (d2.getDate()).toString();
var enddate = new Date();
enddate.setDate(d2.getDate() + 7);
var enddate1 = ((enddate.getDate()).toString().length == 1) ? "0" + (enddate.getDate()).toString() : (enddate.getDate()).toString();
// alert(enddate1 + "hello");
var month2 = ((d2.getMonth() + 1).toString().length == 1) ? "0" + (d2.getMonth() + 1).toString() : (d2.getMonth() + 1).toString();
var endatemonth = ((enddate.getMonth() + 1).toString().length == 1) ? "0" + (enddate.getMonth() + 1).toString() : (enddate.getMonth() + 1).toString();

//alert(new Date().setDate(d2.getDate() + 7));
document.getElementById('<%=lblHeaderDate1.ClientID %>').innerHTML = startdate + "/" + month2 + "/" + d2.getFullYear();
document.getElementById('<%=lblHeaderDate2.ClientID %>').innerHTML = enddate1 + "/" + endatemonth + "/" + enddate.getFullYear();
// testnew();
}
});

<% if (Convert.ToString(Session["LanguageID"])=="IS")
{ %>
jQuery("#datepicker").datepicker(jQuery.datepicker.regional['is']);
<% } %>

//jQuery("#datepicker").datepicker(jQuery.datepicker.regional['is']);


//hover states on the static widgets
jQuery('#dialog_link, ul#icons li').hover(
function () { jQuery(this).addClass('ui-state-hover'); },
function () { jQuery(this).removeClass('ui-state-hover'); }
);
});

但是它向我显示错误。任何人都可以帮助我如何编写 if 条件来设置 datepicker attribue$("defaultDate: parseInt(location.search.indexOf('did=')) >= 0 ? getDefaultDateVal() : new Date(),").datepicker?

最佳答案

你想做什么?

<% if (parseInt(location.search.indexOf('did=')) >= 0) { %>
defaultDate: getDefaultDateVal(),
<% } %>

parseInt显示 javascript 但 <%显示 asp 的服务器端代码块

为什么不只在服务器端做呢?试试这个

<% if (System.Web.HttpContext.Current.Request.QueryString.ToString().Contains("did=")) { %>
defaultDate: getDefaultDateVal(),
<% } %>

关于javascript - if javascript 中 .datepicker 属性的条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16894075/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com