猿问

触发option事件的js怎么来写?

触发option事件的js怎么来写?


慕少森
浏览 436回答 2
2回答

饮歌长啸

<div><select id="sel1" onchange="selChange(this)"><option value='1'>A</option><option value='2'>B</option><option value='3'>C</option><option value='4'>D</option><option value='5'>E</option></select></div><script type="text/javascript" >function selChange(obj){var oi = obj.options[obj.selectedIndex].value;var ot = obj.options[obj.selectedIndex].innerText;var ajax = BuildAjaxModel();ajax.onreadystatechange=function(data){if(ajax.readyState==4){data = ajax.responseText;alert(data);}}ajax.open("GET","doRender.aspx?id="+oi,true);ajax.send(null);}function BuildAjaxModel(){var xmlHttp;try{// Firefox, Opera 8.0+, SafarixmlHttp=new XMLHttpRequest();}catch (e){// Internet Explorertry{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}catch (e){alert("Cant Build AJAX!");return false;}}}return xmlHttp;}</script>

慕田峪7331174

<select onchange="go(this.value);"><option value="1" selected>1</option><option value="2">2</option></select> <script>go(val){ if(val==1) go_1(); else if(val==2) go_2(); }</script>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答