1. 获取radio的值
$("input[name='radioname'][checked]").val();
其中radioname为单选按钮的name.
原生JS获取:
var radioSex=document.getElementsByName("sex").length;
2. Checkbox全选
<input id="selectAll" name="id_check " type="checkbox" onClick="selectALL(this)" />
function selectALL(obj){
$("input[name='id_check']").each(function (){
$(this).attr('checked',obj.checked);
});
}
3. 获取选中的Checkbox
var chkObj = $("input[name='id_check']:checked");
for ( var i=0 ; i < chkObj.size(); i++ ){
$('#' + $(chkObj[i]).val()).remove();
}
4. 控制HTML元素显示与隐藏
<tr id="showSeparateLine" style="display:inline" ><td>隐藏与显示</td></tr>
jQuery实现:
$("#showSeparateLine").hide();
$("#showSeparateLine").show();
JS CSS控制:
document.getElementById("showSeparateLine").style.visibility="visible"; //显示
document.getElementById("showSeparateLine").style.visibility="hidden"; //隐藏
document.getElementById("showSeparateLine").style.display = 'none'; //隐藏
document.getElementById("showSeparateLine").style.display = 'inline'; //显示
注意:jQuery实现方式,会将TR行隐藏,而JS CSS实现方式这回留下TR行空白!