首页  >  问答  >  正文

如何通过 onblur 事件获取输入值?

我试图通过 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 文件中的控制台日志进行打印。

现在显示错误消息,告诉您这是不可能的

P粉818088880P粉818088880180 天前377

全部回复(1)我来回复

  • P粉029327711

    P粉0293277112024-04-04 00:45:23

    我在这里复制了错误的导出,但现在是正确的。这不是问题

    回复
    0
  • 取消回复