1.
原生JavaScript判断是否Touch屏幕
3.用正则和document .location.search 获取URL的值
</pre><pre code_snippet_id="252965" snippet_file_name="blog_20140324_1_7059274" name="code" class="html">function isTouchScreen(){
return (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch);
}
2.自动加载js文件
if (!((window.DocumentTouch && document instanceof DocumentTouch) || 'ontouchstart' in window)) {
var script = document.createElement("script");
script.src = "plugins/af.desktopBrowsers.js";
var tag = $("head").append(script);
}
3.用正则和document .location.search 获取URL的值
要获取当前页面URL的参数,可能大家第一个想到是使用 window.location.href 或者是document.location.href ,获取结果诸如http://www.xxx.com/?aa=xx&bb=xx ;但是其实我们需要的只是:?aa=xx&bb=xx。这种形式可以使用 document.location.search 这个属性获取。
如果我想要获取该URL后面参数aa的值该怎么弄呢?常见的方式可能是这样:
function ( param ){
var url = window . location . toString ();
url = url . split ( ' ? ' );
if ( typeof (url [ 1 ]) == ' string ' ) {
url = url [ 1 ]. split ( ' & ' );
for (i = 0 ;i < url . length ;i ++ )
{
s = url [ i ]. split ( " = " );
if ( s[ 0 ] == " param " ) return s[ 1 ];
}
}
return null ;
}
改用document.location.search和正则获取参数将使代码更加简洁:
function getParameter (sProp )
{
var re = new RegExp (sProp + " =([^\&]*) " , " i " );
var a = re . exec (document . location . search );
if (a == null )
return null ;
return a [ 1 ];
};
4. $.ui.useOSthemes=false的理解
5. $.ui.autoLaunch=false的理解
添加 20140612
采用正则表达式获取地址栏参数:( 强烈推荐,既实用又方便!)
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
;
}
// 调用方法
alert(GetQueryString(
"参数名1"
));
alert(GetQueryString(
"参数名2"
));
alert(GetQueryString(
"参数名3"
));
添加20140710
js获取当前域名
<script language="javascript">
//获取域名 host = window.location.host; host2=document.domain; //获取页面完整地址 url = window.location.href; |