首頁  >  問答  >  主體

如何透過 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 天前376

全部回覆(1)我來回復

  • P粉029327711

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

    我在這裡複製了錯誤的導出,但現在是正確的。這不是問題

    回覆
    0
  • 取消回覆