jquery select demo
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>test</title><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script> <script>$(document).ready(function(){$("input").click(function(){var val = $("input").val();alert(val);});$("input").click(function(){$('input').attr("checked",'2');//$('input').get(2).checked=true; //这种写法也可以});$("input").click(function(){$("input").each(function(){alert($(this).attr("value"));});});$("input").click(function(){$("input").get(1).checked = true;});$("input").click(function(){$("input").attr("checked",true);/* $("input").each(function(){ $(this).attr("checked",true); });*/});$("input").click(function(){$("input").attr("checked",'');/* $("input").each(function(){ $(this).attr("checked",''); });*/});$("input").click(function(){var val = $("select").val();alert(val);});$("input").click(function(){//var val = $("select").find("option:selected").text();//var val = $("select option").text();var val = $("select option:selected").text();alert(val);});$("input").click(function(){//$("select").get(0).selectedIndex = 1; //same$("select").selectedIndex = 1;});$("input").click(function(){$("select").empty();});});</script></head><body> Are you male or femal? <br><input type="radio" name="gender" checked value="male">male<br><input type="radio" name="gender" value="female">female<br><input type="radio" name="gender" value="gay">gay<br><input type="button" value="获得radio选中的值" name="radioBtn1">&nbsp;&nbsp;<input type="button" value="设gay为被选项" name="radioBtn2"><hr> Which fruit do you like?<br><input type="checkbox" name="fruit" value="apple">apple<br><input type="checkbox" name="fruit" value="strawberry">strawberry<br><input type="checkbox" name="fruit" value="mango">mango<br><input type="checkbox" name="fruit" value="cherry">cherry<br><input type="checkbox" name="fruit" value="leechee">leechee<br><input type="button" value="获取checkbox的选中值" name="btn3">&nbsp;&nbsp;<input type="button" value="love strawberry" name="btn4"><br><br><input type="button" value="全选" name="btn5">&nbsp;&nbsp;<input type="button" value="取消全选" name="btn6"><hr> where is your hometown?<select name='hometown'><option value='shandong'>山东</option><option value='sichuang'>四川</option><option value='shanghai'>上海</option></select><br><br><input type='button' name='btn7' value='select被选中的value值'>&nbsp;&nbsp;<input type='button' name='btn8' value='select被选中的文本值'>&nbsp;&nbsp;<input type='button' name='btn9' value='设置‘四川’为当前选中值'>&nbsp;&nbsp;<input type='button' name='btn10' value='清空下拉框'></body></html>
页:
[1]