簡體   English   中英

如何通過 onblur 事件獲取輸入值?

[英]How can I get the input value with onblur event?

我正在嘗試使用 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 文件中的控制台日志進行打印。

現在顯示錯誤消息,告訴您這是不可能的

我在這里錯誤地復制了導出,但現在是正確的。 這不是問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM