【问题标题】:How do I store data inside a div tag into database?如何将 div 标签内的数据存储到数据库中?
【发布时间】:2016-02-22 12:02:51
【问题描述】:

我正在使用像 http://www.jque.re/plugins/forms-controls/quick.tag/ 这样的 jquery 来创建快速标签。快速标签存储在一系列 div 标签中,如下所示

<div id="taglist">
    <div class="tag">
        <a class="close">x</a>
        Red
    </div>
    <div class="tag">
        <a class="close">x</a>
        Blue
    </div>
    <div class="tag">
        <a class="close">x</a>
        Green
   </div>
</div>

如何使用“红色”“蓝色”和“绿色”的值插入数据库?对不起,我是新手。谢谢。

【问题讨论】:

    标签: jquery html database


    【解决方案1】:

    1- 你需要使用 javascript 从你想要的 div 中获取数据,你还需要像 PHP 这样的服务器端语言

    2- 当您标记 Jquery 时,我假设您将其包含在 html &lt;head&gt;&lt;/body&gt; 之前

    3- 你如何使用 jquery?看下一个例子

    $(document).ready(function(){
      var arrayofcolors = [];
      $('#taglist > .tag').each(function(){
        var thisColor = $(this).text().replace('x' , '').trim().toLowerCase();
         arrayofcolors.push(thisColor);
      });
      alert(arrayofcolors);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <div id="taglist">
        <div class="tag">
            <a class="close">x</a>
            Red
        </div>
        <div class="tag">
            <a class="close">x</a>
            Blue
        </div>
        <div class="tag">
            <a class="close">x</a>
            Green
       </div>
    </div>

    关于将arrayofcolors传递给php并将其保存到数据库中,您需要使用$.ajax()方法..并像使用它一样

    $.ajax(function(){
      url : 'to your php url here',
      method : 'POST',
      data : {arrayofcolors : arrayofcolors},
      success : function(data){
        // returned data from php file
        alert(data);
      }
    });
    

    在你的 php 文件中

    <?php
      echo $_POST['arrayofcolors'];
    ?>
    

    此步骤将使用您的颜色返回警报

    【讨论】:

    • 不使用 php 部分,但这正是我需要的,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多