我有一个图像图标,点击后应导航到另一页
' <input type="image" id="dataReview_' + templates[i].dataFileKey + '" title="Data Review" src="Images/datareview.png" style="height: 15px; width: 15px" onclick="dataReview_tasks(this); return false;"/>\n' +
在下面的dataReview_tasks()函数中
function dataReview_tasks(inputOb)
{
var info = new IOInfo(inputObj);
var id = info.key(0);
var tdLastDateId = "lastRun_" + id;
var decoded_lastRunDate = decodeURIComponent(trim($("#" + tdLastDateId).text())).split(" ")[0];
var lastRunDate = encodeURIComponent(decoded_lastRunDate);
window.location('<%= ResolveUrl("~/GUI/DataReviewNEW.aspx") %>');
我应该将ID和lastRunDate作为cookie。我该怎么做呢。
我不确定为什么它在我调试时没有保持值54,我是新的Javascript并且不确定我是否在document.cookie中正确地提供它们任何帮助都非常感谢
答案 0 :(得分:1)
function dataReview_tasks(inputOb){
var info = new IOInfo(inputObj);
var id = info.key(0);
var tdLastDateId = "lastRun_" + id;
var decoded_lastRunDate = decodeURIComponent(trim($("#" + tdLastDateId).text())).split(" ")[0];
var lastRunDate = encodeURIComponent(decoded_lastRunDate);
var tCookiename = '<%= this.CookieDataFileKey %>'; //This is your '$DataFileKey' placeholder from codebehind
var tCookievalue = {id: id, lastRunDate: lastRunDate}; //Since there are two values, we are passing an object.
//Setting the actual cookie
document.cookie = [tCookiename, JSON.stringify(tCookievalue)].join('=');
window.location('<%= ResolveUrl("~/GUI/DataReviewNEW.aspx") %>')
}
function readCookie(n){
var tC = document.cookie || '';
tS = tC.split(n + '=').pop().split(';')[0];
return JSON.parse(tS)
}
readCookie('$DataFileKey')
是的,当然可以单独设定值:
//Settings '$DataFileKey'
document.cookie = ['<%= this.CookieDataFileKey %>', id].join('=');
//Settings '$DataWhatever'
document.cookie = ['<%= this.CookieDateCompleteEnd %>', lastDateRun].join('=');
function readCookie(n){
return (document.cookie || '').split(n + '=').pop().split(';')[0]
}
readCookie('$DataFileKey')
答案 1 :(得分:0)
使用以下代码:
document.cookie = "$(<%= this.CookieDataFileKey %>) =" + id +'"';