我试图通过 onblur 事件获取值输入,但当我使用 JS 模块时,它不起作用。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Calculadora de receitas e despesas</title>
<script type="module" src="main.js"></script>
</head>
<body>
<table>
<tr>
<td >Franchise Fee</td>
<td class="value">
<input type="input" class="form__field" placeholder="R$" name="franchise-fee" id='franchiseFee' onblur="getFranchiseFee()" required />
</td>
</tr>
</table>
</body>
GetElements.mjs 模块文件:
function getFranchiseFee(franchiseFee){
franchiseFee = document.getElementById('franchiseFee');
// console.log(franchiseFee.value);
return parseFloat(franchiseFee.value);
}
export {getFranchiseFee};
main.js 文件:
import {getFranchiseFee} from './GetElement.mjs';
console.log(getFranchiseFee());
我尝试使用模块中的函数在控制台日志上显示输入的值,并使用 main.js 文件中的控制台日志进行打印。
现在显示错误消息,告诉您这是不可能的
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我在这里复制了错误的导出,但现在是正确的。这不是问题