我有以下选择选项代码:
<select name="startTime" id = "startTime" onchange = "javascript:timeChange();">
<c:choose>
<c:when test="${param.cid != null}">
<option value="<c:out value="${timevalue}"/>" selected><c:out value="${time}" /></option>
<option value="<c:out value="-"/>"><c:out value="Choose time"/></option>
</c:when>
<c:otherwise>
<option value="<c:out value="-"/>" selected><c:out value="Choose time" /></option>
</c:otherwise>
</c:choose>
<option value="10:00:00" >10:00</option>
<option value="11:00:00" >11:00</option>
<option value="12:00:00" >12:00</option>
<option value="13:00:00" >13:00</option>
<option value="14:00:00" >14:00</option>
<option value="15:00:00" >15:00</option>
<option value="16:00:00" >16:00</option>
<option value="17:00:00" >17:00</option>
<option value="18:00:00" >18:00</option>
<option value="19:00:00" >19:00</option>
<option value="20:00:00" >20:00</option>
<option value="21:00:00" >21:00</option>
</select>
并且还有以下ajax代码:
$.ajax({
url: "temporary_checking.jsp",
type: "POST",
data: data,
async: true,
timeout:6000,
dataType: "html",
success: function (data) {
data = data.trim();
var n = data.indexOf("ERROR",0);
if( n > -1 ){
if(data.indexOf("ERROR 2",0) >= 0 ){
alert("Error to allocate time slot");
return true;
}
}else{
window.location.reload(false);
if(getCookie('Times') != null || getCookie('Times') != undefined)
{
deleteCookie('Times');
}
setCookie('reload',1,'');
setCookie('zerosecond',1,'');
}
},
error: function(XMLHttpRequest, textStatus, errorThrown){
document.getElementById('startTime').value = "-";
alert("Error to book time slot : " + textStatus + '\n ' + errorThrown);
return false;
}
});
所以,问题是每当它选择一个选项时,例如17:00,那么该值将恢复为默认值,即“选择时间”选项。但是,它在FireFox上没有问题。有解决方案吗提前致谢
答案 0 :(得分:0)
如果你调用函数“window.location.reload(false);”页面将立即重新加载,所有JS状态将丢失,并且此语句之后的代码行将不会被执行。所以最好在重新加载之前设置cookie:
...
} else {
if (getCookie('Times') != null || getCookie('Times') != undefined) {
deleteCookie('Times');
}
setCookie('reload',1,'');
setCookie('zerosecond',1,'');
window.location.reload();
}
...
“false”参数对我没有意义,因为它是默认值: http://www.w3schools.com/jsref/met_loc_reload.asp