javascript - 我应该将“单击”更改为“绑定”吗?它不能一起工作
问题描述
早上好,我有这两个 javascript 代码,但我无法让它们都工作。当两者都嵌入到我的页面中时,负责将文档上传到文件夹的代码停止工作。我在任何地方都看不到错误,我在哪里失败了?提前致谢。
$(function() {
// grab the file input and bind a change event onto it
$('#file').bind("change", function() {
// new html5 formdata object.
$('#botondecarga').hide();
$('#cargando').show();
var formData = new FormData();
formData.append('carpeta', $('#carpeta[name="carpeta"]').val());
//for each entry, add to formdata to later access via $_FILES["file" + i]
for (var i = 0, len = document.getElementById('file').files.length; i < len; i++) {
formData.append("file" + i, document.getElementById('file').files[i]);
}
//send formdata to server-side
$.ajax({
url: "file-upload.php", // our php file
type: 'post',
data: formData,
dataType: 'html', // we return html from our php file
async: true,
processData: false, // tell jQuery not to process the data
contentType: false,
// tell jQuery not to set contentType
success : function(data) {
confirm("Documentos subidos satisfactoriamente.");
location.reload();
},
error : function(request) {
console.log(request.responseText);
}
});
});
});
$(document).ready(function(){
var maxField = 10; //Input fields increment limitation
var addButton = $('.add_button'); //Add button selector
var wrapper = $('.field_wrapper'); //Input field wrapper
var fieldHTML = '<div id="cantidadstock" class="cantidadstock"></div><div class="form-group"><label>Producto</label><select class="form-control select2" name="producto[]" id="producto" required><?php
$clase_newstock->lista_productos_almacen_principal_formulario();
?></select><label>Cantidad</label><input type="number" name="cantidad[]" class="form-control" value=""/><div class="form-group"><label>Fecha recepcion</label><div class="input-group"><div class="input-group-addon"><i class="fa fa-calendar"></i></div><input type="text" id="fecha_recepcion" name="fecha_recepcion[]" class="form-control"></div><div class="form-group"><label for="nombre">N albaran proveedor</label><input type="text" class="form-control" id="albaran_proveedor" name="albaran_proveedor[]" placeholder="El numero de albaran del proveedor..."></div><div class="form-group"><label for="precio">Precio</label><input type="number" class="form-control" id="precio" name="precio[]" placeholder="Precio...(Solo números y punto para decimales) "></div><br><a href="javascript:void(0);" class="remove_button btn btn-warning">Quitar producto</a></div>'; //New input field html
var x = 1; //Initial field counter is 1
//Once add button is clicked
$(addButton).click(function(){
//Check maximum number of input fields
if(x < maxField){
x++; //Increment field counter
$(wrapper).append(fieldHTML); //Add field html
$('.select2').select2();
}
});
//Once remove button is clicked
$(wrapper).on('click', '.remove_button', function(e){
e.preventDefault();
$(this).parent('div').remove(); //Remove field html
x--; //Decrement field counter
});
});
解决方案
推荐阅读
- ios - 验证用户是否使用 Firebase 和 Swift 但使用 FirebaseDatabase - 不是 FIRDatabase
- javascript - 按钮单击事件触发两次
- python - Python:这个 Python 代码(请求)有什么问题?
- .net-core - 如何使用自动生成的 id 在同一事务中添加多个实体?
- react-native - Expo更新到最新版本后的componentWillReceiveProps错误
- java - 无法实现内部“for”循环
- sql-server - 如何获取hierarchyid数据类型列的脚本
- java - springdoc-openapi-maven-plugin配置/apiDocsUrl的作用是什么?
- javascript - 通过单击和拖动进行多选
- c# - 使用 c# ASP.NET MVC 获取视频播放