Iframe
1.在iframe中查找父页面元素的方法:
$('#id', window.parent.document)
2.在父页面中获取iframe中的元素方法:
$(this).contents().find("#id")
3.在iframe中调用父页面中定义的方法和变量:
parent.method
parent.value
4.iframe里用jquery获取父页面body
$(window.parent.document.body)
5.跨Iframe
$("#id",window.parent.frames(2).document);
Table
1.鼠标移动行变色
方法一:jQuery中的hover(fun(),fun())方法,参数一:第一个方法是添加样式功能,参数二:第二个方法是取消样式功能
$("#table1 tr").hover(function(){
$(this).children("td").addClass("hover")
},function(){
$(this).children("td").removeClass("hover")
})
2.倒数第n行
("#table1 tr").eq(-n)
Append方法eg:
<table>
<tr>
<td>xxx</td><td>yyy</td>
</tr>
</table>
应该是将dom层次分清:即将dom各个层上的节点一层一层的添加:
var tr = $("<tr></tr>");
tr.append("<td>xxx</td><td>yyy</td>");
var table = $("<table></table>");
table.append(tr);
$("#div").append(table);
复杂表单元素1.下拉框
$("#formid select[name='country'] option[selected]").text(); //得到下拉菜单的选中项的文本(注意中间有空格)
$('#fomrid select[name="country"]').val(); //得到下拉菜单的选中项的值
$("#select").empty();//清空下拉框
$("<option value='1'>1111</option>").appendTo("#select")//添加下拉框的option
$("#select").attr("value",'-sel3');//设置value=-sel3的项目为当前选中项
$('#select')[0].selectedIndex = 1; //下拉框第二个元素为当前选中值
2,单选框:
$("input[type=radio][checked]").val(); //得到单选框的选中项的值(注意中间没有空格)
$("input[type=radio][value=2]").attr("checked",'checked'); //设置单选框value=2的为选中状态.(注意中间没有空格)
$("input[type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项
3,复选框:
$("input[type=checkbox][checked]").val(); //得到复选框的选中的第一项的值
$("input[type=checkbox][checked]").each(function(){ //由于复选框一般选中的是多个,所以可以循环输出
alert($(this).val());
});
$("[name='rowsPramters_c']").change(function(){
var str="";
$("[name='rowsPramters_c']").each(function(){
if($(this).attr("checked"))//火狐下面 不能用上面的 checkd来 选择 必须这样
str+=$(this).val()+",";
})
str+="type,"//证书类别,默认显示
$("#rowsPramters_hidden").val(str);
});$("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==true){} //判断是否已经打勾