javascript - queryselected/getElementByClass 的值返回值为空
问题描述
当我尝试从另一个模块中查询选择元素时,它总是返回空字符串?应该怎么做才能解决这个问题?该元素存在是因为当我控制台记录它时,该元素就在那里,即使我在 UI 中填写了输入,该值也总是返回空,只是当我按下提交时它返回空。
此外,如果我将代码移动到导出函数的范围内,它就可以工作
下面的代码在函数 footerSubmitSection() 内,该函数被导出到另一个名为 addNewOrderFormMain.js 的模块,其中所有组件都被附加到主容器并导出到 index.js
console.log 返回
// order ID
db.collection('UserDatabase').doc(currentUserID).get().then((doc) => {
function dateForOrder(){
let today = new Date();
let dd = String(today.getDate()).padStart(2, '0');
let mm = String(today.getMonth() + 1).padStart(2, '0');
let yyyy = today.getFullYear();
today = mm+dd+yyyy;
return today
}
let todayOrderNum = db.collection('OrderDatabase').where('OrderDate', '==', `${orderDate}`)
.get()
.then((snapshot) => {
length = snapshot.size + 1;
let salesRepID = doc.data().SaleID
let salesRepName = doc.data().Name
let orderID = salesRepID + dateForOrder()+'-'+ length + "-"+ editversion
console.log(deliveryMethodInput)
if (deliveryMethodInput=== 'Pick Up'){
const pickupLocationInput = document.getElementsByClassName('orderDetailSectionMidPickupLocationSelect')[0].value;
let pickupLocation = pickupLocationInput;
db.collection('OrderDatabase').doc(orderID).set({
PickupLocation:pickupLocation,
ShippingAddress:"",
BusinessName:businessName,
CustomerType:customerType,
BillingAddress:billingAddress,
CustomerPhoneNumber:customerPhoneNum,
DeliveryMethod:deliveryMethod,
ShipOrPickDate:shipOrPickDate,
PaymentMethod:paymentMethod,
Notes:notes,
OrderDate:orderDate,
OrderStatus:orderStatus,
OrderID:orderID,
salesRepID:salesRepID,
salesRepName:salesRepName,
})
db.collection('CustomerDatabase').get().then((snapshot) => {
snapshot.forEach((doc) => {
if(businessNameValue === doc.data().BusinessName){
let customerID = doc.data().CustomerID;
db.collection('OrderDatabase').doc(orderID).update({
CustomerID:customerID,
})
}
})
})
let subtotalArray=[]; /////////////this is the block im having issue with
let sum = 0
const basket = document.getElementsByClassName('orderProductSectionMidItemContainer')
Array.from(basket).forEach((basketItem) => {
const basketItemName = basketItem.getElementsByClassName('orderProductSectionMidDisplayItemNameInput')[0];
const basketItemPrice = basketItem.getElementsByClassName('orderProductSectionMidDisplayPriceInput')[0];
const basketItemQuantity = basketItem.getElementsByClassName('orderProductSectionMidDisplayQuantitiyInput')[0];
const basketItemDiscount = basketItem.getElementsByClassName('orderProductSectionMidDisplayDiscountInput')[0];
const basketItemSubtotal = basketItem.getElementsByClassName('orderProductSectionMidDisplaySubtotal')[0];
subtotalArray.push(basketItemSubtotal.value);
console.log(basketItemName.value)
console.log(basketItemName.value)
console.log(basketItemPrice.value)
console.log(basketItemQuantity.value)
db.collection('OrderDatabase').doc(orderID).collection('Basket').doc('testing').set({
ItemName:basketItemName.value,
ItemPrice:basketItemPrice.value,
ItemQuantity:basketItemQuantity.value,
ItemDiscount:basketItemDiscount.value,
ItemSubtotal:basketItemSubtotal.value ,
})
console.log(subtotalArray)
})
console.log(basket)
for(let i = 0; i < subtotalArray.length; i++){
sum += parseFloat(subtotalArray[i]);
}/////////////block ends here
}else if(deliveryMethodInput === 'Ship'){
db.collection('OrderDatabase').doc(orderID).set({
ShippingAddress:shippingAddress,
PickupLocation:"",
BusinessName:businessName,
CustomerType:customerType,
BillingAddress:billingAddress,
CustomerPhoneNumber:customerPhoneNum,
DeliveryMethod:deliveryMethod,
ShipOrPickDate:shipOrPickDate,
PaymentMethod:paymentMethod,
Notes:notes,
OrderDate:orderDate,
OrderStatus:orderStatus,
OrderID:orderID,
salesRepID:salesRepID,
salesRepName:salesRepName,
})
db.collection('CustomerDatabase').get().then((snapshot) => {
snapshot.forEach((doc) => {
if(businessNameValue === doc.data().BusinessName){
let customerID = doc.data().CustomerID;
db.collection('OrderDatabase').doc(orderID).update({
CustomerID:customerID,
})
}
})
})
}
})
})
解决方案
推荐阅读
- java - 在使用 SpringFox 的 Swagger Docket 配置中忽略 OAuth2 SecurityReference AuhtorizationScope
- python - 如何修复 - TypeError:无法设置内置/扩展类型“set”的属性
- javascript - 如何从表中创建、编辑或删除实体并将其保存到数据库
- pyiron - 如何使用 PyIron 选择网格进行声子计算
- http - 在wireshark中建立了多少个http和https连接?
- python - 如何向后遍历这个压缩表?
- github - GitHub README 图片损坏 - “违反以下内容安全策略指令:“img-src 'self'”
- seaborn - 如何在 seaborn.relplot 中使用向量或键
- merge - m:m 合并的问题(Stata)
- jms - 如何在 qpid JMS 中设置 ContentType