javascript - onClick - 从另一个文件调用函数
问题描述
我有一个与前端链接的功能.js 文件,在这里我想点击一个 div(item1wrapper) 并从我的 index.js 文件中调用一个函数。
在此functionality.js 文件中,我附加了div:
socket.on('response', function (data) {
if (msg.includes('totalPrice')) {
if (parsed.itemPrice.length === 1) {
$('#messages').append($('<li id="messageclient">').append($(`
<div id="message-cont" class="message-cont">
<div class="orderDetailsWrapper">
<div class="detailsHeaderWrapper">
<div class="orderNum"></div>
<div class="customerName"></div>
</div>
<div class="textToCustomer">
<p> Please click on the item you want to return</p>
</div>
<div class="itemBoxWrapper">
<div id ="item1Wrapper" class="item1Wrapper" onclick="">
<div class="item1Title"></div>
<div class="item1Price"></div>
</div>`
)).append($('<div id="client-imgorder">')));
$("#messages").animate({ scrollTop: $("#messages")[0].scrollHeight }, 1000);
$('.customerName').text('Customer name: ' + customerName);
$('.orderNum').text('Order number: ' + orderNum);
$('.item1Title').text('Item: ' + item1Title);
$('.item1Price').text('Price: ' + item1Price);
}
模块导出不起作用,因为它链接到前端?
这是我的 index.js 文件中的函数:
function oneCall() {
itemId = itemIdArray[0];
// matching API get
// getRefundCalc API post.
console.log('ngrokurl' + ngrokUrl)
console.log('domain' + domain)
console.log('orderId' + orderId)
console.log('itemId' + itemId)
/*
The Purchase date must be in the future
*/
rp(optionsPOST1)
.then(function (parsedBody) {
Match = parsedBody.Match;
if (Match) {
console.log('Match is true');
httpRequest.post(
`${ngrokUrl}/${domain}/${orderId}`,
{
json:
{
"line_items": [
{
"line_item_id": itemId, "quantity": 1
}
]
}
},
function (error, resp, body) {
if (!error && resp.statusCode == 200) {
console.log(body)
response = responseToFrontEnd
data = [details.chatuser, response]
io.of('/main').to(socket.id).emit('response', data);
}
else {
console.log('error' + error)
}
}
)
// include getRefundCalc within here
} else {
console.log('Match is false');
response = `I'm sorry but your item fell out of the refund policy. Please check the purchase date of your item or if it falls under the minimum price.`
}
});
}
目前“onclick”是空的,因为它没有工作,当我点击这个function.js文件中的那个div时,我想调用那个函数!它必须在功能文件之外,因为它需要节点模块并且需要在套接字函数中!
解决方案
推荐阅读
- asp.net - Blazor 服务器端应用上的子 Blazor 应用
- java - Error in if statement of Singly Linked List Program
- perl - 在 Perl 中将数组传递给 getopt
- javascript - 计算unix时间后替换数组中的值
- python - 熊猫根据条件移动行
- json - 如何在scala中读取json数组的所有元素
- .net - 为什么我在使用 NuGet 时会做这样的噩梦?
- javascript - 是否可以在浏览器版本的 babel 中使用白名单?
- c# - F#/C#:如何从库中导入符号常量
- php - 访问对象变量的关系会改变变量