0

これがヘッダーです。結果は新しいページに表示されますが、コードが実行されているのと同じページに結果を表示したいと思います。助けてください。

function calculate() {
    var width = document.getElementById("width");
    width1 =  width.options[width.selectedIndex].text;  
    var height = document.getElementById("height");
    var height1 =  height.options[height.selectedIndex].text;    
    var calculate = width1 * height1 * 3;
    result.innerHTML = "<div>" + calculate + "</div>";
}

Choose Width
<select id="width" name="height" onchange="calculate()">
    <option>1</option>
    <option>1</option>
</select>
<br/>
Choose Heiht
<select id="height" name="height" onchange="calculate()">
    <option>1</option>
    <option>2</option>      
</select>
4

2 に答える 2

1

使用できます:

Choose Width:

<select id="width" name="height" onchange="calculate()">
    <option>1</option>
    <option>2</option>
</select>

    <br/>

   Choose Height

<select id="height" name="height" onchange="calculate()">
    <option>1</option>
    <option>2</option>      
</select>
<div id="result"></div>

そしてjavascriptは次のようにする必要があります:

function calculate()
{
    var width = document.getElementById("width");
    width1 =  width.options[width.selectedIndex].text;  
    var height = document.getElementById("height");
    var height1 =  height.options[height.selectedIndex].text;    
    var calculate = width1*height1*3;
    var result = document.getElementById("result");
    result.innerHTML = calculate;
}
于 2013-02-26T07:07:57.010 に答える
0

HTML コードに div として含める必要がresultあります。次に、結果を配置するために innerHTML または innerText を実行する必要があります
新しいタグを追加します (HTML コードに)

<div id="result"></div>

JSでこのdiv要素を更新します

var result = document.getElementById("result");
result.innerText = calculate;
于 2013-02-26T07:10:54.173 に答える