在javascript中读取cookie

read cookies in javascript

本文关键字:cookie 读取 javascript      更新时间:2023-09-26

在文本框onchange属性上,我调用了一个javascript函数既然我写了这些,

function testbox1()
{
var strline1side1 = document.frmartwork.side1textbox1.value;
document.cookie="lineside1="+strline1side1.replace(" "," ")+";path=/;";
}

我想给这个"lineside1" cookie值当页面被重新加载

window.onload=function()
{
document.frmartwork.side1textbox1.value = "here i want that cookie "

}

我该怎么做?

你应该使用jquery cookie插件

function testbox1()
{
var strline1side1 = document.frmartwork.side1textbox1.value;
$.cookie('lineside1',strline1side1.replace(" "," "));
}
window.onload=function()
{
document.frmartwork.side1textbox1.value = $.cookie('lineside1')

}

如果你正在使用jQuery -使用jQuery。饼干插件。使用起来非常简单。

$.cookies('cookiename') // get value
$.cookies('cookiename', value) // set value
function testbox1()
{
    $.cookies('lineside1', $('#side1textbox1').val());
}
$(document).ready(function(){
    $('#side1textbox1').val($.cookies('lineside1'));
});

另外,如果你开始使用jQuery -使用它:)