第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在 Javascript 中選擇 HTML 輸入元素并更改值來(lái)運(yùn)行方程式?

如何在 Javascript 中選擇 HTML 輸入元素并更改值來(lái)運(yùn)行方程式?

藍(lán)山帝景 2023-07-06 18:28:53
我正在嘗試使用輸入字段來(lái)更改方程的某些值,以便給出合成角度。我已設(shè)法選擇默認(rèn)值并將答案記錄到控制臺(tái),但是當(dāng)我嘗試更改這些值時(shí)沒(méi)有任何變化?我的最終目標(biāo)是擁有一個(gè)應(yīng)用程序,您可以在其中輸入這 3 個(gè)值并點(diǎn)擊“提交”,然后它將在屏幕上輸出答案。因此,對(duì)于默認(rèn)值,它將輸出“角度為:36.92°”const height = document.getElementById("height").value;const trussSpan = document.getElementById("trussSpan").value;const rafter = document.getElementById("rafter").value;const hypot = Math.hypot(height, (trussSpan / 2));const t1 = Math.atan2(height, (trussSpan / 2)) * 180 / Math.PI;const t2 = Math.atan2(rafter, hypot) * 180 / Math.PI;const result = Number((t1 - t2)).toFixed(2);console.log("height: " + height);console.log("Truss Span: " + trussSpan);console.log("Rafter Depth: " + rafter);console.log("Hyptonuse: " + hypot);console.log("Angle 1: " + t1);console.log("Angle 2: " + t2);console.log("The angle of the truss is: " + result + "°");div{    text-align: center;    color: maroon;    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;    font-weight:400;}    h1 {    text-align: center;    color: maroon;    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;    font-weight:400;}<!DOCTYPE html><html><head>    <title>Angle Finder</title>    <link rel="stylesheet" href="angleFinder.css"></head><body>          <div>            <label for="height">Height: </label>            <input type="number" id="height" value="2000">            <label for="trussSpan">Span: </label>            <input type="number" id="trussSpan" value="5000">            <label for="rafter">Rafter Depth: </label>            <input type="number" id="rafter" value="97">            <br>            <input type="submit" id="submit">       </div>            <h1> Angle Finder</h1>    <script src="angleFinder.js"></script>  </body></html>
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個(gè)贊

一些更改:首先,<h2 id="theResult"></h1>在角度查找器后面添加一個(gè),您將在其中顯示結(jié)果。


其次,將 js 文件的代碼放入名為getResult().


第三,在html文件中,調(diào)用該getResult()函數(shù)作為input的onclick事件。“input”標(biāo)簽中的“onclick”屬性將您的按鈕鏈接到 javascript 函數(shù),以便每當(dāng)單擊該按鈕時(shí)都會(huì)調(diào)用該函數(shù)。


<input type="submit" id="submit" onclick="getResult()">


最后,添加document.getElementById("theAnswer").innerHTML = result;到函數(shù)的末尾getResult(),以便它將更新標(biāo)簽的innerHTML <h2 id="theAnswer">。


請(qǐng)參閱以下更改:


html 文件:

<!DOCTYPE html>


<html>


<head>

    <title>Angle Finder</title>

    <link rel="stylesheet" href="angleFinder.css">

</head>


<body>

    


      <div>

            <label for="height">Height: </label>

            <input type="number" id="height" value="2000">


            <label for="trussSpan">Span: </label>

            <input type="number" id="trussSpan" value="5000">


            <label for="rafter">Rafter Depth: </label>

            <input type="number" id="rafter" value="97">

            <br>


            <input type="submit" id="submit" onclick="getResult()">

       </div>


        

    <h1> Angle Finder</h1>

    <h2 id="theResult"></h1>


    <script src="angleFinder.js"></script>  

</body>


</html>


JavaScript 文件:


function getResult() {

    const height = document.getElementById("height").value;

    const trussSpan = document.getElementById("trussSpan").value;

    const rafter = document.getElementById("rafter").value;

    const hypot = Math.hypot(height, (trussSpan / 2));

    const t1 = Math.atan2(height, (trussSpan / 2)) * 180 / Math.PI;

    const t2 = Math.atan2(rafter, hypot) * 180 / Math.PI;

    const result = Number((t1 - t2)).toFixed(2);


    console.log("height: " + height);

    console.log("Truss Span: " + trussSpan);

    console.log("Rafter Depth: " + rafter);

    console.log("Hyptonuse: " + hypot);

    console.log("Angle 1: " + t1);

    console.log("Angle 2: " + t2);

    console.log("The angle of the truss is: " + result + "°");


    document.getElementById("theResult").innerHTML = result;

}


查看完整回答
反對(duì) 回復(fù) 2023-07-06
  • 1 回答
  • 0 關(guān)注
  • 148 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)