javascript - 如何一次存储 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">×</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个表...
类别子类别
子类别
子类别二
发布表
都连接到外键 Post 表结构
尝试保存类别值时,子类别值,子类别二值错误是
我怎样才能在 db Modal show 这样的时间不同位置存储 3 个值
像这样的模态
解决方案
MySQL 很可能在 STRICT 模式下尝试更改列以允许为空:
ALTER TABLE `posts` CHANGE `subcategory2` `subcategory2` varchar NULL
或者尝试运行
SET GLOBAL sql_mode='' or
推荐阅读
- r - R - 如何在二进制矩阵中提取组之间的唯一交集?
- python - Seaborn 情节 - 按时间顺序排列
- angular - 订阅之外未定义的布尔值?
- reactjs - react-router-dom with react hooks 不重定向到正确的路由
- python - 匹配文本
- java - 为什么抛出异常时我的方面代码不运行?
- python - 格式化时可以将字符串转换为大写吗
- ios - 在 tableViewHeader 中添加一个按钮,就像默认的 iOS 一样
- python - ImportError:没有名为“flask.ext”的模块
- python - 迭代作为列表的字典值以创建新的字典列表