js获取select下拉框选中的的值和判断checkbox是否选中状态html:
<select id="lib_select" name="">
<option value="1">text1</option>
<option value="2">text2</option>
</select>
<input type="checkbox" value="1" id="lib_checkbox" />
javascript原⽣的⽅法:
var ElementById("lib_select");
var index=libselect.selectedIndex; //拿到选中项(option)的索引(index)
libselect.options[index].value; //拿到选中项options的value
libselect.options[index].text; //拿到选中项options的text
jquery获取下拉框选中值
var is_checked = ElementById("lib_checkbox").checked; // true or false
jquery⽅法
var options=$("#lib_select option:selected");
var _value=options.val();
var _text = ();
var is_checked = $("#lib_checkbox").is(':checked'); // true or false
or
var is_checked = $("#lib_checkbox").get(0).checked ; // true or false
注意:⽤.attr('checked') ⽅法不能动态的取到checked状态的,
var is_checked = $("#lib_checkbox").attr('checked'); // 如果设置了checked属性,则返回checked; 没设⽽返回 undefined
发表评论