将onchange函数下拉到html中

时间:2012-05-03 20:53:00

标签: javascript html

我想使用Dropdown onchange函数进入html传递值,它在提交按钮中工作正常,但是我想使用Dropdown onchange,请帮忙怎么做?

<form method="post" action=" ">
    <div align="center">
        <select name="value">
            <option value="">Show Value</option><br />
            <option value="2"> 2  </option><br />
            <option value="5"> 5  </option><br />
            <option value="10"> 10 </option><br />
            <option value="20"> 20 </option><br />
        </select>
        <input type="submit" name="submit" value="Submit">
    </div>
</form>

1 个答案:

答案 0 :(得分:5)

您应该将onChange添加到<select>元素中,如此

<form method="post" action=" ">
    <div align="center">
        <select name="value" onChange="this.form.submit()">
            <option value="">Show Value</option><br />
            <option value="2"> 2  </option><br />
            <option value="5"> 5  </option><br />
            <option value="10"> 10 </option><br />
            <option value="20"> 20 </option><br />
        </select>
        <input type="submit" name="submit" value="Submit">
    </div>
</form>