前端小技巧

来源:互联网 发布:梦幻西游法宝算法 编辑:程序博客网 时间:2024/05/18 16:13

前端小技巧


td中的内容自动换行:

<td width="1000" style="vertical-align: top;word-wrap: break-word;word-break: break-all;"></td>

固定div的显示位置、设定大小(X轴、Y轴都有滚动条):

<div style="width: 100%;height: 500px;overflow: scroll;position:absolute; left: 1px;top: 70px;">

fieldset标签:

<fieldset>        <legend>health information</legend>         height: <input type="text" />         weight: <input type="text" /></fieldset>

返回上页:
(1)window.location.href=”;
(2)window.history.go(返回第几页,也可以使用访问过的URL);[说明:-1表示上一页;-0表示刷新;-2表示上两页]
(3)window.history.back();

刷新页面:
(1)window.location.reload(); [刷新本页面]
(2)opener.location.reload(); [刷新父页面]
(3)self.opener.location.reload(); [子窗口刷新父窗口]
(4)parent.另一FrameID.location.reload(); [刷新另一个框架的页面]
(5) [打开窗口时刷新]
(6) [关闭窗口时刷新]

打开新窗口:

window.open (''page.html'',''newwindow'',''height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no'');

去掉超链接激活时的边框线:
(1)如果,要是这样去修改网站中所有的链接来实现该效果,肯定是不现实的。要通过在CSS的链接属性里加一条语句,可以做到批量修改:

a{    blr:expression(this.onFocus=this.blur());}

注:这个好像只有IE才有效果,FireFox中还是有边框虚线出现。

(2)CSS样式:

<style type="text/css">    .hideFocus{hide-focus: expression(this.hideFocus=true);} </style>

冻结行(不合并行的情况下有用):

style="background-color: #ababab;position: relative;top: expression(this.offsetParent.scrollTop);"

showModalDialog:

window.showModalDialog(sUrl, "ypbh:"+ypbh+"", status=no;dialogWidth=1105px;dialogHeight=500px;menu=yes;resizeable=no;scroll=yes;center=yes;edge=raise");

子窗口给父窗口赋值:
老写法:

window.parent.document.getElementById("cInvName").value = str;

jQuery 的写法:

$("#cInvName", window.parent.document).val(str);

添加代码:
老写法:

window.parent.document.getElementById("divObj").innerHTML="hello 114look.com";

jQuery写法:

$("#divObj", window.parent.document).html("hello 114look.com"); 

window.open.$("#divObj").val("0123");

获取iframe中的document对象:

$(window.frames["iframe"].document).find("input[name='abc']").val();

获得iframe中的iframe对象:

$(window.frames["iframe1"].frames["iframe2"].document).find("input:radio").attr("checked","true");