Jquery:创建多个实体

发布于 2024-10-14 07:08:36 字数 2894 浏览 3 评论 0原文

我正在为 iPhone 网站创建一个便签提醒应用程序。目标是让用户创建尽可能多的“便签”——所有数据都将保存在本地存储中。

我这里有一个即时贴的工作原型:

    $( function() {
        $('#sticky-edit').bind( 'taphold', function( e ) {
            alert( 'You tapped and held!' );
            var thetext = localStorage.getItem("sticky");
            $(".sticky-text").html('<input id="sticky-input" type="text" value="'+thetext+'" />');
      } ); 
      
        $('#sticky-submit').bind( 'taphold', function( e ) {
            var data = $("#sticky-input").val();
            alert('Notes Saved!');
            localStorage.setItem("sticky", data);
            $(".sticky-text").text(localStorage.getItem("sticky")).show();
      } );  

    } );

    $(".sticky-text").text(localStorage.getItem("sticky")).show();
#stickies li {
    position: relative;
    width: 200px;
    min-height: 100px;
    margin: 25px auto;
    padding: 15px;
    background: #f1f3a2;
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(247,247,210,1)), to(rgba(240,242,155,1)));
    background: -moz-linear-gradient(top, rgba(247,247,210,1), rgba(240,242,155,1));
    -webkit-box-shadow: 0 2px 12px rgba(0,0,0,.5);
    -moz-box-shadow: 0 2px 12px (rgba(0,0,0.5));
    box-shadow: 0 1px 2px #000;
    -webkit-transform: rotate(-.5deg); 
    -moz-transform: rotate(-.5deg); 
    -o-transform: rotate(-.5deg);   
    text-align: center;
    color: #000;
    text-shadow: white 1px 1px 0px;
    list-style: none;
}

#stickies li:nth-child(even) {
    -webkit-transform: rotate(.5deg); 
    -moz-transform: rotate(.5deg); 
    -o-transform: rotate(.5deg);     
}

#stickies li::before {
    content: ' ';
    display: block;
    position: absolute; 
    left: 65px;
    top: -15px;
    width: 75px;
    height: 25px;
    z-index: 2;
    background-color: rgba(243,245,228,0.5);
    border: 2px solid rgba(255,255,255,0.5);
    -webkit-box-shadow: 0 0 5px #888;
    -moz-box-shadow: 0 0 5px #888;
    box-shadow: 2px 2px 2px #000;
    -webkit-transform: rotate(-3deg); 
    -moz-transform: rotate(-3deg); 
    -o-transform: rotate(-3deg); 
}

#stickies li:nth-child(even)::before {
    -webkit-transform: rotate(3deg); 
    -moz-transform: rotate(3deg); 
    -o-transform: rotate(3deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="stickies">
    <li>
        <p class="sticky-text">Hello</p>
        <a id="sticky-edit">Edit</a>
        <a id="sticky-submit">Submit</a>
    </li>
</ul>

现在我需要做的就是弄清楚如何允许用户创建尽可能多的便签,每个便签都有自己的本地存储区域。使用 jquery 可以实现这一点吗?或者使用 php 来实现这一点会更容易吗?

I am creating a stickies reminder application for an iphone website. The goal is to have the user to create as many "stickies" as he wants - all the data would be saved with localstorage.

I have a working prototype of the stickies here:

    $( function() {
        $('#sticky-edit').bind( 'taphold', function( e ) {
            alert( 'You tapped and held!' );
            var thetext = localStorage.getItem("sticky");
            $(".sticky-text").html('<input id="sticky-input" type="text" value="'+thetext+'" />');
      } ); 
      
        $('#sticky-submit').bind( 'taphold', function( e ) {
            var data = $("#sticky-input").val();
            alert('Notes Saved!');
            localStorage.setItem("sticky", data);
            $(".sticky-text").text(localStorage.getItem("sticky")).show();
      } );  

    } );

    $(".sticky-text").text(localStorage.getItem("sticky")).show();
#stickies li {
    position: relative;
    width: 200px;
    min-height: 100px;
    margin: 25px auto;
    padding: 15px;
    background: #f1f3a2;
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(247,247,210,1)), to(rgba(240,242,155,1)));
    background: -moz-linear-gradient(top, rgba(247,247,210,1), rgba(240,242,155,1));
    -webkit-box-shadow: 0 2px 12px rgba(0,0,0,.5);
    -moz-box-shadow: 0 2px 12px (rgba(0,0,0.5));
    box-shadow: 0 1px 2px #000;
    -webkit-transform: rotate(-.5deg); 
    -moz-transform: rotate(-.5deg); 
    -o-transform: rotate(-.5deg);   
    text-align: center;
    color: #000;
    text-shadow: white 1px 1px 0px;
    list-style: none;
}

#stickies li:nth-child(even) {
    -webkit-transform: rotate(.5deg); 
    -moz-transform: rotate(.5deg); 
    -o-transform: rotate(.5deg);     
}

#stickies li::before {
    content: ' ';
    display: block;
    position: absolute; 
    left: 65px;
    top: -15px;
    width: 75px;
    height: 25px;
    z-index: 2;
    background-color: rgba(243,245,228,0.5);
    border: 2px solid rgba(255,255,255,0.5);
    -webkit-box-shadow: 0 0 5px #888;
    -moz-box-shadow: 0 0 5px #888;
    box-shadow: 2px 2px 2px #000;
    -webkit-transform: rotate(-3deg); 
    -moz-transform: rotate(-3deg); 
    -o-transform: rotate(-3deg); 
}

#stickies li:nth-child(even)::before {
    -webkit-transform: rotate(3deg); 
    -moz-transform: rotate(3deg); 
    -o-transform: rotate(3deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="stickies">
    <li>
        <p class="sticky-text">Hello</p>
        <a id="sticky-edit">Edit</a>
        <a id="sticky-submit">Submit</a>
    </li>
</ul>

Now all I need to do is figure out how to allow the user to create as many stickies as they want each with its own local storage area. Is this possible with jquery or would it be easier to use php to accomplish this?

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

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

发布评论

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

评论(1

≈。彩虹 2024-10-21 07:08:36

我在 Flash 中做过一次。本地存储区是什么意思?您可以让用户像这样创建任意数量的: http://jsfiddle.net/NegYd/14/ 使用 javascript/jquery。关键是:

function appendSticky(){
     var e= document.getElementById("submittext").value;
     $("#stickies").append("<li>"+e+"</li>");
     $.post("store.php", { text: e} );//you'll have to submit user information
}

和 html:

<input id="submittext" type='text'/>
<input type='submit' value='add note' onClick="javascript:appendSticky();"/>

然后在您的 store.php 中将便签存储到 MySQL 数据库中。 $sql="INSERT.."

我建议使用 float:left; 使用随机 margin-left 值而不是列表来组织便签带来终极的便利贴感觉。或者更好的是,让便利贴可拖放。

I did this in Flash once. What do you mean by local storage area? You can let the user make as many as he wants like this: http://jsfiddle.net/NegYd/14/ using javascript/ jquery. Key being:

function appendSticky(){
     var e= document.getElementById("submittext").value;
     $("#stickies").append("<li>"+e+"</li>");
     $.post("store.php", { text: e} );//you'll have to submit user information
}

and the html:

<input id="submittext" type='text'/>
<input type='submit' value='add note' onClick="javascript:appendSticky();"/>

Inside your store.php you then store the stickies into a MySQL Database. $sql="INSERT.."

I suggest organizing the stickies with float:left; with a random margin-leftvalue rather than a list for the ultimate post-it feel. Or even better, make the post-its drag-and-dropable.

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