我试图获取一个文本框的值,该文本框将在所有HTML加载完毕后通过功能前缀添加。
我单击一个按钮来提交表单,但是无法获取类数量的值 我正在使用的PHP Codeigniter:
$(".pro_body").prepend(
//I add more class information
);
$(document).ready(function () {
$("#btn_button_xuathang").on("click", function (e) {
//$("body").on("click", "#btn_xuathang", function () {
e.preventDefault();
var obj = $(".e_data_table_tinh");
show_ajax_loading(obj);
var $url = $(".form_products").attr("action");
var list_products = [];
$.each($(".e_data_table_tinh .infomation"), function (index) {
list_products.push
({
sku: $(this).children(".sku").text(),
title: $(this).find(".title").val(),
quantity: $(this).find(".quantity").val(),
variant_id: $(this).children(".variant_id").text(),
variant_title: $(this).children(".variant_title").text(),
location: $(this).find(".location").attr('data-location'),
cat_id: $(this).children(".cat_id").text(),
note: $(this).find(".note").text(),
product_id: $(this).children(".product_id").text(),
});
});
var date = $(".date_time").attr("data-date");
var laixe = $(".laixe").attr("data-laixe");
var order_number = $(".laixe").attr("data-order-number");
var list_id = [];
$.each($(".quantity_xuathang"), function (index) {
//var variant_id_load = $(this).attr("data-variant-id");
//$("body").on("click", "#btn_xuathang", function () {
//var quantity = $(document).find(".quantity_"+variant_id_load).attr('data-val');
//});
list_id.push
({
variant_id: $(this).attr("data-variant-id"),
//quantity: $(this).parent().parent().find(".quantity").attr('data-val'),
quantity: $(this).parent().parent().find(".quantity").val(),
data_da_xuat: $(this).attr("data-da-xuat"),
quantity_need: $(this).attr("data-quantity-need")
});
});
console.log(list_products);
var list_cat_id = $(".pro_body").attr("data-result-catid");
var data_note = $(".pro_body").attr("data-note");
$.ajax({
url: $url2,
type: "POST",
data: {
date: date,
laixe: laixe,
order_number : order_number,
list_id: list_id,
list_products: list_products,
},
dataType: "json",
success: function (data) {
if (data.state == 1) {
$(".e_data_table_tinh img[title='Loading']").parent().css({
"display": "none"
});
remove_ajax_loading();
var url_xuathang = $(".form_products").attr("data-href");
var input = $("<input>").attr("type", "hidden").attr("name", "laixe").val($(".laixe").attr("data-laixe"));
var input2 = $("<input>").attr("type", "hidden").attr("name", "date").val($(".date_time").attr("data-date"));
var input3 = $("<input>").attr("type", "hidden").attr("name", "shipper_id").val($(".laixe").attr("data-id-laixe"));
var input5 = $("<input>").attr("type", "hidden").attr("name", "kho").val($(".name_kho").attr("data-kho"));
var input6 = $("<input>").attr("type", "hidden").attr("name", "name_kho").val($(".name_kho").attr("data-name-kho"));
var input7 = $("<input>").attr("type", "hidden").attr("name", "list_products").val(JSON.stringify(list_products));
var input8 = $("<input>").attr("type", "hidden").attr("name", "list_cat_id").val(list_cat_id);
var input9 = $("<input>").attr("type", "hidden").attr("name", "data_note").val(data_note);
var input10 = $("<input>").attr("type", "hidden").attr("name", "sorting").val($(".sorting").val());
var input11 = $("<input>").attr("type", "hidden").attr("name", "data_xuathang").val(JSON.stringify(list_id));
setTimeout(function () {
location.reload();
}, 1000);
var form = $("<form method='POST' action='" + url_xuathang + "' target='_blank'>");
form.append(input);
form.append(input2);
form.append(input3);
form.append(input5);
form.append(input6);
form.append(input7);
form.append(input8);
form.append(input9);
form.append(input10);
form.append(input11);
$("body").append(form);
form.submit();
//hoi co in ra cai phieu xuat hang ko
//nhay ra trang moi va reload lai trang nay
} else {
$(".e_data_table_tinh img[title='Loading']").parent().css({
"display": "none"
});
remove_ajax_loading();
alert("chua co san pham nao dc them vao inventory");
}
},
error: function (a, b, c) {
console.log("Có lỗi ");
$(".e_data_table_tinh img[title='Loading']").parent().css({
"display": "none"
});
//location.reload();
},
complete: function (jqXHR, textStatus) {
}
});
});
});
在已加载div
的情况下,没有问题,但是对于新的div
则不起作用,并返回:
结果是“未定义”
我试图用以下方法解决它:
$(document).ready(function(){
}).