Web小應用

bei_fang_du_lang發表於2016-09-19

1、js獲取查詢字串

function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}

2、js獲取文字寬度

function testWordWidth(fontStyle,fontSize,text){
	text = text.replace("%","好");
	var testDiv = $("<div style = 'position:absolute;left:-100px;top:-100px; font-weight:normal;'></div>");
	testDiv.css("font-family",fontStyle).css("font-size",fontSize).html(text);
	$('body').append(testDiv);
	var returnObj = {};
	returnObj.width = testDiv.width();
	returnObj.height = testDiv.height();
	testDiv.remove();
	return returnObj;
}


相關文章