【问题标题】:Jquery: Create multiple entitiesJquery:创建多个实体
【发布时间】:2011-06-16 14:48:28
【问题描述】:

我正在为一个 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 更容易做到这一点?

【问题讨论】:

  • 基于教程 - 可能会在以后更改它。
  • CSS+1 真的很好

标签: php jquery local-storage


【解决方案1】:

我在 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值来组织便签,而不是为最终的便利贴感而列出的列表。或者更好的是,将便利贴做成可拖放的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多