2013-02-14 36 views
0

我目前有這段代碼,這是確定一個給定長度的高度和翼展。我真的很喜歡將結果輸入爲英尺和英寸的測量結果,以及由此產生的相同測量結果的翼展和高度。我不介意它是否使用了引路人或時期。英尺高度/長度發生器?

<SCRIPT LANGUAGE="LiveScript"> 
    function wings(form) { 
     form.wingspan.value = (form.length.value * .75) * 2 
     form.height.value = form.length.value * .5 
    } 
</SCRIPT> 

<TABLE> 
    <TR> 
     <TD>Dragon Length:</TD> 
     <TD><INPUT TYPE="text" NAME="length" SIZE=15 /></TD> 
    </TR> 
    <TR> 
     <TD>Dragon Wingspan:</TD> 
     <TD><INPUT TYPE="text" NAME="wingspan" SIZE=15 /></TD> 
    </TR> 
    <TR> 
     <TD>Dragon Height:</TD> 
     <TD><INPUT TYPE="text" NAME="height" SIZE=15 /></TD> 
    </TR> 
    <TR> 
     <TD><INPUT TYPE="button" VALUE="Calculate" ONCLICK="wings(this.form)" /></TD> 
    </TR> 
</TABLE> 

</FORM> 
+0

你的代碼是無效的,我編輯它,並加入2 missings'' – 2013-02-14 02:06:58

回答

0

是否正在將您的瀏覽器加載?

如果你是,那麼LiveScript將不會在大多數情況下運行。您可能想要使用JavaScript或JQuery來編程。

下面是一個讓你開始使用的代碼片段,帶有內嵌評論以供解釋。注意:我真的不適合你算什麼...你應該嘗試這樣做,你自己的做法:

<!DOCTYPE html> 
<html> 
<head> 
    <!-- You need this line so you can load the JQuery functions that you will be using --> 
    <script src="http://code.jquery.com/jquery-latest.js"></script> 
</head> 
<body> 

<form id="wings"> 
<TABLE> 
<TR><TD>Dragon Length:</TD><TD> 
    <INPUT TYPE ="text" id="winglength" SIZE=15</TD></TR> 
</TABLE> 
</form> 

<!-- ID of this element is called "trigger" and will be used for clicking --> 
<div id="trigger">Click me to calculate the Wingspan and Height!</div> 

<!-- This div tag is called "wingspan" --> 
<div id="wingspan">Wingspan is: </div> 

<!-- Can you write the HTML code for "height" here? --> 

<script> 

    // Everything in here will run when your page is loaded 
    $(document).ready(function() { 

     // When you click on the DIV tag called "trigger", you run this cod below. 
     $("#trigger").click(function() { 

      // "append" the wing length to the HTML tag above: the # refers to id called winglength 
      $("#wingspan").append($("#winglength").val()); 

      // How you calculate the "height" is left as an exercise for the original poaster! 
     }); 
    }); 
</script> 

</body> 
</html> 
+0

我運行它的一個論壇,所以它只是插入的職位之一。我不確定這是否會改變任何事情 - 正如我所說的,我很新手。 – 2013-02-14 03:32:43

+0

什麼論壇?它可能會影響事物 - 許多論壇不允許您在其上運行代碼。 – Irwin 2013-02-14 03:37:15

+0

簡易機器;你可以在[link](http://katila.second-pass.net/index.php?topic=2649.msg12270#msg12270)中看到上面和另一個。但是,他們不會讀出腳和英寸,這就是我所追求的:) – 2013-02-14 03:43:33

0

由於沒有插件或庫,這裏就是你們的榜樣的工作...

取看看這個例子:http://jsfiddle.net/BtC4K/

的Javascript:

function wings(){ 
    var lenght = document.getElementsByName("length")[0]; 
    var wingspan = document.getElementsByName("wingspan")[0]; 
    var height = document.getElementsByName("height")[0]; 

    wingspan.value = (lenght.value * 0.75) * 2; 
    height.value = lenght.value * 0.5; 
} 

HTML:

<table> 
    <tr> 
     <td>Dragon Length:</td> 
     <td><input type="text" name="length" SIZE=15 /></td> 
    </tr> 
    <tr> 
     <td>Dragon Wingspan:</td> 
     <td><input type="text" name="wingspan" SIZE=15 readonly /></td> 
    </tr> 
    <tr> 
     <td>Dragon Height:</td> 
     <td><input type="text" name="height" SIZE=15 readonly /></td> 
    </tr> 
    <tr> 
     <td><button onclick="wings()">Calculate</button></td> 
    </tr> 
</table>