在 JavaScript 中读取 cookie

发布于 2024-12-07 11:50:55 字数 421 浏览 0 评论 0原文

在文本框 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 "


}

我该怎么做?

On textbox onchange property i have called one javascript function
In that I have written this,

function testbox1()
{

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

}

I want to assign this "lineside1" cookie value when page is reload

window.onload=function()
{

document.frmartwork.side1textbox1.value = "here i want that cookie "


}

How can i do this?

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

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

发布评论

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

评论(2

他是夢罘是命 2024-12-14 11:50:55

您应该使用 jquery cookie 插件

function testbox1()
{

var strline1side1 = document.frmartwork.side1textbox1.value;
$.cookie('lineside1',strline1side1.replace(" "," "));

}

window.onload=function()
{

document.frmartwork.side1textbox1.value = $.cookie('lineside1')


}

You should use jquery cookie plugin

function testbox1()
{

var strline1side1 = document.frmartwork.side1textbox1.value;
$.cookie('lineside1',strline1side1.replace(" "," "));

}

window.onload=function()
{

document.frmartwork.side1textbox1.value = $.cookie('lineside1')


}
若有似无的小暗淡 2024-12-14 11:50:55

如果您使用 jQuery - 使用 jQuery.cookies 插件。使用起来非常简单。

$.cookies('cookiename') // get value
$.cookies('cookiename', value) // set value

function testbox1()
{
    $.cookies('lineside1', $('#side1textbox1').val());
}

$(document).ready(function(){
    $('#side1textbox1').val($.cookies('lineside1'));
});

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

If you are using jQuery - use jQuery.cookies plugin. It's quiet simple to use.

$.cookies('cookiename') // get value
$.cookies('cookiename', value) // set value

function testbox1()
{
    $.cookies('lineside1', $('#side1textbox1').val());
}

$(document).ready(function(){
    $('#side1textbox1').val($.cookies('lineside1'));
});

Also, if you start using jQuery - use it :)

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