“简单地记一下这段时间所遇到的前端知识点”
1.用于重新计算iframe高度
function getHeight() {
var iframe = parent.document.getElementById('iframe0');
var _navLeft = parent.document.getElementById('nav-left');
if ($(iframe).length > 0) {
$(iframe).height(getHeightFromIframe(iframe));
$(_navLeft).height(getHeightFromIframe(iframe) + 102);
// IE8 下该事件只触发了一次
if (iframe.attachEvent) {
iframe.attachEvent("onload", function () {
$(iframe).height(getHeightFromIframe(iframe));
$(_navLeft).height(getHeightFromIframe(iframe) + 102);
});
} else {
iframe.onload = function () {
$(iframe).css("min-height", "530px");
$(iframe).height(getHeightFromIframe(iframe));
$(_navLeft).height(getHeightFromIframe(iframe) + 102);
};
}
}
}
function getHeightFromIframe(selector) {
return $(selector).contents().find('body').height() + 200;
}
2.PC端窗口缩放,页面布局不发生改变,只要在该页面上加上min-width:?px就行了。
3.请求数据(很多种请求数据的方式,这里我只是为自己做个笔记)
function getdata(url, parm, fn, errfn) {
$.ajax({
url: urlPrefix + url,
data: parm,
type: "POST",
dataType: "json",
cache: false,//不取浏览器缓存
async: true,//异步
success: function (data) {
fn(data);
}, error: function (err) {
if (err.status == "409") {//系统定义409为session超时,转换提示信息
alert('用户信息丢失,请重新登录!');
//window.location.href = "/Login";
}
hideloading();
//alert("出错了" + JSON.stringify(err));
errfn && errfn(err)
}, complete: function () {
}
});
}
4.获取浏览器地址栏?后面的参数
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
5.iframe的回到顶部
function backtotop() {
window.parent.scrollTo(0, 0);
}
6.请求页面
function getHTML(url, parm, fun) {
$.ajax({
url: urlPrefix + url, //请求的url地址
dataType: "html", //返回格式为json
async: true, //请求是否异步,默认为异步,这也是ajax重要特性
data: parm, //参数值
type: "GET", //请求方式
beforeSend: function () {
//请求前的处理
},
success: function (req) {
fun(req);
},
complete: function () {
},
error: function () {
popWindow(0, '获取页面失败!', 1400);
$("#about").modal();
}
});
}
7.格式化日期
dateForm(new Date()) 获取当前系统时间
//只有一位数时前面补0
function appendzero(obj) {
if (obj < 10) return "0" + "" + obj;
else return obj;
}
function dateForm(time) {
var data = new Date(time);
var year = data.getFullYear(); //获取年
var month = data.getMonth() + 1; //获取月
var day = data.getDate(); //获取日
time = year + "-" + appendzero(month) + "-" + appendzero(day);
return time;
}
8.计算6个月前的时间
function lessSixMonth(time) {
var startDate = new Date(time);
var firstdate = new Date(startDate.setMonth(startDate.getMonth()-6));
return firstdate;
}
var firstdate = new Date(year, month, 1); //取指定月的第一天
var endDate = (new Date(firstdate.getTime() - 1000 * 60 * 60 * 24));//获取指定月最后一天
9.悬浮
//有iframe用window.parent.document,没有用document
$(window.parent.document).scroll(function () {
var scrollheight = parseInt($(window.parent.document).scrollTop());
if (scrollheight >= 660) {
$("#chartTab").css({
"position": "fixed",
"top": parseInt($(window.parent.document).scrollTop()) - 145 + "px"
});
} else if (scrollheight < 660) {
$("#chartTab").css({
"position": "relative",
"top": "0px"
});
}
});
10.在IE8不支持background-size,解决办法用过滤
.f-content{
margin-top:40px;
height: 480px;
font-size: 16px;
text-align: center;
background-image: url('D:/BF/Desktop/DFI COC/images/funnel.png');
background-size: cover;
-ms-filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='D:/BF/Desktop/DFI COC/images/funnel.png',sizingMethod='scale')";
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='D:/BF/Desktop/DFI COC/images/funnel.png',
sizingMethod='scale');
}
<!--[if IE 8]>
<style type="text/css">
.f-content{
margin-top:40px;
height: 480px;
font-size: 16px;
text-align: center;
background-image: none;
background-size: cover;
-ms-filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='D:/BF/Desktop/DFI COC/images/funnel.png',sizingMethod='scale')";
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='D:/BF/Desktop/DFI COC/images/funnel.png',
sizingMethod='scale');
}
</style>
<![endif]-->
网上说图片最好用绝对路径,貌似用相对路径也行呵!
暂时记下这几点。。。。