English 中文(简体)
简单编码,用 co显示习俗内容
原标题:Simple code to show custom content with cookies

我是设计者,不是方案设计者,我必须在这里求助。 我确信,这对一名方案管理员来说是非常简单的。 我需要的是一种守则,使用户能够选择检查箱,以建立显示网页上相应图像的厨师。

例如,如果用户选择箱子[a]和[c],则将安装一个 co,并在网页上展示一些地方。

<img src=“a.gif”> <img src=“c.gif”>

如果用户返回表格并选择不同的选择,则将展示其他图像。 基本上,这一文字是允许用户根据他们可用的选择,对网页的某些部分进行定制。 库克群岛不应过期,这样用户就能够回过自己的习惯网页。 我需要用javascript,最好是使用jQuery,如果这样做会简化法典,因为我已经为其他职能装上了支架。

我应用了你的法典,但却没有 create。 我在《html法典》中失踪了什么?

<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.cookie.js"></script>
<script type="text/javascript" src="yourcookiecode.js"></script>

</head>

<BODY>
<form>
<input type="checkbox" name="a" onClick="SetCookie( name , this.name, exp);">
<input type="checkbox" name="b" onClick="SetCookie( name , this.name, exp);">
<input type="checkbox" name="c" onClick="SetCookie( name , this.name, exp);">
</form>
</body>
</html>
最佳回答

UPDATED CODE:

HTML:

<input type="checkbox" name="a">
<input type="checkbox" name="b">
<input type="checkbox" name="c">

<div id="somediv"></div>

JAVASCRIPT:

$(document).ready(function() {
    $( :checkbox ).each( function(){
         //Search if checkbox exist in cookie
        var checkbox = $(this);
         var getname = checkbox.attr( name );
         var searchCookie = $.cookie(getname);

        if(searchCookie != null) {
         //Was in div, now add img
            $( :checkbox[name*=" +getname+ "] ).attr( checked ,true);
            $( #somediv ).append( <img src=" +getname+ .gif" /> );
        }
    });


    $( :checkbox ).change( function() {
        var checkbox = $(this);
        var isChecked = checkbox.is( :checked );
        var getname = checkbox.attr( name );
        if(isChecked) {
         //Add to cookie, add img
             $.cookie(getname,  true , { expires: 7 });   
             $( #somediv ).append( <img src=" +getname+ .gif" /> );
        } else {
         //Unchecked, remove from cookie
            $( #somediv ).find( img[src*=" +getname+ "] ).remove();
            $.cookie(getname, null);
        }
    });
});

You need the cookie plugin:

那么,你可以做这样的事情:

$(:checkbox).each( function(){
     //Search if checkbox exist in cookie
     var getname = checkbox.attr( name );
     var searchCookie = $.cookie(getname);

    if(searchCookie != null) {
     //Was in div, now add img
        $( #somediv ).append( <img src=" +getname+ .gif" /> );
    }
});


$(:checkbox).change( function() {
    var checkbox = $(this);
    var isChecked = checkbox.is( :checked );

    if(isChecked) {
         var getname = checkbox.attr( name );
     //Add to cookie, add img
         $.cookie(getname,  true , { expires: 7 });   
         $( #somediv ).append( <img src=" +getname+ " /> );
    } else {
     //Unchecked, remove from cookie
        $.cookie(getname, null);
    }
});
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签