javascript - 如何通过触发点击两个函数来发送相同的输入值?
问题描述
我想将相同的输入值发送到两个函数,但它不起作用。让我展示一下我的代码摘要。
const btn = document.querySelector('.btn')
btn.addEventListener('click',getTogether)
function getTogether(event){
event.preventDefault();
const country = document.querySelector('.input-text').value ;
getChart(country);
getGlobal(country)
}
function getChart(country){
......
}
function getGlobal(country){
......
}
是否可以将相同的输入值作为参数发送给两个函数,或者有没有更好的方法?请告诉我。
解决方案
我不确定你的问题是什么,但下面的代码有帮助吗?
const btn = document.querySelector('.btn')
const country = document.querySelector('.input-text')
btn.addEventListener('click', getTogether)
function getTogether(event) {
event.preventDefault()
getChart(country.value)
getGlobal(country.value)
}
function getChart(country) {
console.log("getChart called with:", country)
}
function getGlobal(country) {
console.log("getGlobal called with:", country)
}
<input type="text" class="input-text" />
<button class="btn">Click Me</button>
推荐阅读
- vuejs2 - VueJS - Vee-Validate:调用方法/函数来评估结果的自定义规则?
- php - 显示 json 字符串中的所有对象
- python - 如何将 MaxPooling1D 与 Conv1D 一起使用
- pandas - 除了其他列之外,pandas 还导出以前的列
- python - 如何修复 Python/Django 迁移错误
- sql - SQL Server 查询以获取表中的列列表以及数据类型、长度、唯一性、非空值、主键、外键及其引用
- python - 你可以完全循环一个范围,但从第 n 个元素开始?
- c++ - 工作线程中的 GDI 打印机设备上下文随机失败
- javascript - 使用ajax刷新表
- mfc - 获取 COleDateTime::Format 以返回波兰月“January”的“stycznia”而不是“styczeń”