通过选择onChange调用javascript函数 [英] Calling javascript function from a select onChange
本文介绍了通过选择onChange调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我到目前为止:
HTML
< div style =float:left>类型:< select id =selectoronChange =jsfunction()>
< option value =Pyr>金字塔式< / option>
< option value =Lin> In-Lines< / option>
< option value =Sym>对称< / option>
< option value =Nsym>非对称< / option>
< / select>
< / div>
Javascript
函数jsfunction(){
alert(hi);
}
它不起作用,对我而言,我无法计算为什么。我找到的这种性质的大多数其他问题都提示在调用函数 - 我已经获得或者
解决方案
<!DOCTYPE html>
< html>
< head>
< script>
函数jsfunction(){
alert(hi);
}
< / script>
< / head>
< body>
< select id =selectoronchange =jsfunction()>
< option value =Pyr>金字塔式< / option>
< option value =Lin> In-Lines< / option>
< option value =Sym>对称< / option>
< option value =Nsym>非对称< / option>
< / select>
< / body>
< / html>
有效。您在 onchange
。
中犯了一个错误
So I have a simple HTML select box, and a javascript alert function. I want the select box to have an onchange event that will call the javascript alert function. This is what I have so far:
HTML
<div style="float: left">Type: <select id="selector" onChange="jsfunction()">
<option value="Pyr">Pyramidally</option>
<option value="Lin">In-Lines</option>
<option value="Sym">Symmetrically</option>
<option value="Nsym">Non-Symmetrically</option>
</select>
</div>
Javascript
function jsfunction(){
alert("hi");
}
It doesn't work and for the life of me I can't figure out why. Most other questions of this nature I've found suggest ""
around calling the function - which I've got or making the onChange
'c' capital, which I also have. Any possible help? I'd be very grateful.
解决方案
<!DOCTYPE html>
<html>
<head>
<script>
function jsfunction(){
alert("hi");
}
</script>
</head>
<body>
<select id="selector" onchange="jsfunction()">
<option value="Pyr">Pyramidally</option>
<option value="Lin">In-Lines</option>
<option value="Sym">Symmetrically</option>
<option value="Nsym">Non-Symmetrically</option>
</select>
</body>
</html>
It works. You made a mistake in onchange
.
这篇关于通过选择onChange调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文