首页 > 解决方案 > 如何一次存储 3 个值相同的文本框?

问题描述

<script type="text/javascript">
document.getElementById("subcategory").addEventListener("change", function() {
   console.log(this.value);    
});
   $(function(){
        $('.categoryList').click(function(){
          console.log($(this).attr("name"));

          var cat_id = event.target.value;
          var url = "http://localhost:8000/api/getSubcategory/"+cat_id;
          $.ajax({
              type: "GET",
              url: url,
              dataType: "JSON",
              success: function(res)
              {
                var html = "";
                $.each(res, function (key, value) {
                     html += "<li class="+'subcategorys'+" value="+key+" name="+value+">"+value+" </li>";
                });
                 $('#subcategory').html($(html).addClass('subcategoryList'));
                     $('.subcategorys').on('click', function(event) {
                      console.log($(this).attr("name"));
                       var  subcat_id =event.target.value;
    
                         console.log(subcat_id);
                     });
              }
          });
        });

    });
$(document).ready(function() {
    $('#subcategory').on('click', function(event) {
       
        
       var  subcat_id =event.target.value;
    
          console.log(subcat_id);
          var url = "/api/getSubcategorytwo/"+subcat_id;
          $.ajax({
              type: "GET",
              url: url,
              dataType: "JSON",
              success: function(res)
              {
                
                var html = "";
                $.each(res, function (key, value) {
                     html += "<li value="+key+">"+value+"</option></li>";
                });
                $("#subcategorytwo").html(html);

              }
          });
         });


    $('#subcategorytwo').on('click', function(event) {

    var  opt_subcat_two =event.target.value;
    var opt = $(event.target).text();    
    console.log(opt,opt_subcat_two);

$( "#fetchvalue" ).replaceWith("<input type='text' class='form-control' name='subcategorytwo' value="+opt_subcat_two+" id='fetchvalue' data-toggle='modal' data-target='#myModal'> "+opt+"</input>");
     $('#myModal').modal('hide');
     $('.modal-backdrop').remove();
    });
   });

</script>
<input  type="text" class="form-control" name="subcategorytwo" id="fetchvalue" data-toggle="modal" data-target="#myModal" ></input>

  <!-- The Modal -->
  <div class="modal" id="myModal">
<div class="modal-dialog modal-lg" >
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <a type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</a>
        </div>
        
        

                            <div class="modal-body">
                      <div class="row">
                          <table class="table table-striped">
                              <thead>
                              </thead>

                                <tbody class="table">
                                    <tr>
                                      <td style="background-color: green">
                                       <div class="col-md-7" >
                                            @foreach($categories as $category)
                                               <option  class="categoryList" name="{{$category->category}}" value="{{$category->id}}">{{$category->category}}</option>
                                            @endforeach
                                        </div>
                                      </td>
                                         <td>
                                            <div class="col-md-7">
                                              <ul style="list-style: none" id="subcategory"></ul>
                                            </div>
                                         </td>
                                         <td>
                                            <div class="col-md-7">
                                              <ul style="list-style: none" name="subcategorytwo" id="subcategorytwo" ></ul>
                                            </div>
                                         </td>     
                                    </tr>
                              </tbody>
                            </table>
                            
                      </div>
                    </div>
                          </div>
    </div>
  </div>

</div>

这是javascript代码和模态代码...我总共有4个表...

  1. 类别子类别

  2. 子类别

  3. 子类别二

  4. 发布表

    都连接到外键 Post 表结构

尝试保存类别值时,子类别值,子类别二值错误是

我怎样才能在 db Modal show 这样的时间不同位置存储 3 个值

像这样的模态

标签: javascriptjqueryajaxlaravel

解决方案


MySQL 很可能在 STRICT 模式下尝试更改列以允许为空:

ALTER TABLE `posts` CHANGE `subcategory2` `subcategory2` varchar NULL

或者尝试运行

SET GLOBAL sql_mode='' or 

推荐阅读