我一直在负责构建一个非常简单的应用程序,已在2行一系列的下拉列表中后,当选择2,一个简单的功能地连接了2个值,并给出一个输出旁边,像这样:阻止刷新页面发射功能
dropdown1 dropdown2 Output
我想要得到的是,一旦第二个下拉值选择功能运行并显示它说:output
输出。但目前,似乎发生的是输出显示在新窗口中。
这里是我到目前为止(HTML):
<form>
<select id="test">
<option>Arena/Quantum Barcelona LTBC</option>
<option>Arena/Quantum Spain LTES</option>
</select>
<select id="name" onchange="tryThis()">
<option>Name</option>
<option>Name1</option>
</select>
</form>
的JavaScript:
function tryThis() {
var string, string1 = '';
var e = document.getElementById("test");
string = e.options[e.selectedIndex].text;
var a = document.getElementById("name");
string1 = a.options[a.selectedIndex].text;
document.write(string+'_'+string1);
}
我是不是做比它需要这个比较难?
要么创建一个新的元素,要么设置一个现有元素的内容; 'document.write'会消灭你的页面。我建议使用JS库来使所有这些更容易。 – 2011-12-20 12:14:03