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>
4

2 回答 2

0

With no plugins or libraries, here is your example working...

Take a look at this example: 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>
于 2013-02-14T02:53:28.153 回答
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>
于 2013-02-14T02:34:16.150 回答