2008年6月19日
function gethost(url)
{
var result = url.match("^http:\/\/([^\/:]*)");
if(result[1])
{
var domain = result[1].match("[0-9a-zA-Z-]*\.(com\.tw|com\.cn|com\.hk|net\.cn|org\.cn|gov\.cn|ac\.cn|bj\.cn|sh\.cn|tj\.cn|cq\.cn|he\.cn|sx\.cn|nm\.cn|ln\.cn|jl\.cn|hl\.cn|js\.cn|zj\.cn|ah\.cn|fj\.cn|jx\.cn|sd\.cn|ha\.cn|hb\.cn|hn\.cn|gd\.cn|gx\.cn|hi\.cn|sc\.cn|gz\.cn|yn\.cn|xz\.cn|sn\.cn|gs\.cn|qh\.cn|nx\.cn|xj\.cn|tw\.cn|hk\.cn|mo\.cn|com|net|org|biz|info|cn|mobi|name|sh|ac|io|tw|hk|ws|travel|us|tm|cc|tv|la|in|中国|公司|网络)$");
...
2008年6月19日
//obj-要获取其页面坐标的元素
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curleft,curtop];
...
2008年6月11日
function GetLocationParam(param){ //获取页面参数
var request = {
QueryString : function(val) {
var uri = window.location.search;
var re = new RegExp("" +val+ "=([^&?]*)", "ig");
return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
...
Tags: 参数
2008年4月29日
[CODE_LITE]function setCookie(name,value)
{
var Days = 30;
var exp = new Date(); //new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
...
2008年4月25日
in_array
in_array -- 检查数组中是否存在某个值
说明
bool in_array ( mixed needle, array haystack [, bool strict] )
在 haystack 中搜索 needle,如果找到则返回 TRUE,否则返回 FALSE。
[CODE_LITE]function in_array(needle, haystack) {
if(typeof needle == 'string' || typeof needle == 'number') {
...
2008年4月22日
<SCRIPT LANGUAGE="JavaScript">
<!--
function formatFloat(src, pos)
{
return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
}
alert(formatFloat("1212.2323", 2));
//-->
</SCRIPT>
还有如下几种方法:
[CODE_LITE]var test=88888.234;
...
2008年4月11日
传统办法:在标签内加属性 代码多,修改难
<a href="link1.htm" onfocus="this.blur()">link1</a>
<a href="link1.htm" onfocus="this.close()">link1</a>
<a href="link1.htm" hidefocus="true">link1</a>
<a href="link1.htm" hidefocus="hidefocus">link1</a>
2008年3月24日
function trim(str) {
return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1');
}
2008年3月21日
function isIE() {
if(document.all) return true;
return false;
}
2008年3月21日
//以字母开头,由数字和字母组成
var patn = /^[a-zA-Z]+[a-zA-Z0-9]+$/;
if(!patn.test(username)){
alert('会员登录名只能由英文字母或数字组成(不支持中文、不能以数字开头)。');
return;
}