最近写代码的时候常碰到的一些问题
把具体的问题和 解决代码贴下:
使用iframe多框架的一些方法:
HTML部分
<div> <iframe src="showgoods.aspx" style="width:100%; height:1000px; overflow:hidden; display:block; border:0px;" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes"></iframe> </div>
JQ部分
var ifbrand=false; var ifprice=false; var ifsize=false; var ifCPUCount=false; var ifCPU=false; function urld(){ var loadpage="showgoods.aspx?id=1"; if(ifbrand==true){ loadpage+="&brand="+$("#ifbrandcount").text(); }else{ loadpage+="&brand=1"; } if(ifprice==true){ loadpage+="&price="+$("#ifpricecount").text(); }else{ loadpage+="&price=1"; } if(ifsize==true){ loadpage+="&size="+$("#ifsizecount").text(); }else{ loadpage+="&size=1"; } if(ifCPUCount==true){ loadpage+="&CPUCount="+$("#ifCPUCountcount").text(); }else{ loadpage+="&CPUCount=1"; } if(ifCPU==true){ loadpage+="&SearchCPU="+$("#ifCPUcount").text(); }else{ loadpage+="&SearchCPU=1"; } return loadpage; }; $("#searchsql button").click(function(){ try{ var loadpage=urld(); $("iframe")[0].src=loadpage; //src重置后 iframe将会自动重载 return false; }catch(e){ alert(e); } });
设置iframe的src的值
src重置后 iframe将会自动重载
若想不改变SRC的值 重载 可以使用window.location.reload() 进行重载
若想要将iframe内的内容在新页面中打开 则使用window.open(url)即可
重点:
1.在未设置iframe的scrolling="no" allowtransparency="yes"时 width可以设为100% 但height设为100%貌似是无效的 以后可以直接复制这个iframe的代码
2.iframe里的内容排版大小应以DIV的大小而定 因为设有overflow:hidden; 多余部分会不显示
除此之外 另外就是编辑iframe的自动适应高度问题
这里就直接贴代码好了
$("iframe:eq(0)").load(function(){ try{ $(this).height($(this).contents().find(".position-one").height()); }catch(e){ alert(e); } });
find(".position-one").height(); 大家可以代替为body的高度
具体的我没试过 大家自己去试试
iframe做出来的效果 应该具体在于伪异步 它比较符合W3C的标准 同时对flash等的支持也比较好