Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Tuesday, May 10, 2011

Javascript延时

[cc lang="javascript"]
setTimeout(function() {
homes.removeClass('shot');
}, 30000);[/cc]

Tuesday, May 3, 2011

jQuery removeClass

[cc lang="javascript"]
$('td[class^="input_"]').removeClass(function (index, class) {
var matches = class.match (/spf_c\d+/g) || [];
return (matches.join (' '));
});
[/cc]

Monday, March 14, 2011

Thursday, November 25, 2010

用的Javascript函数var_dump(),implode()

[cc lang="javascript"]
// 检测是否为整数
function isInteger( str ){
var regu = /^[-]{0,1}[0-9]{1,}$/;
return regu.test(str);
}

function implode (glue, pieces) {
var i = '', retVal='', tGlue='';
if (arguments.length === 1) {
pieces = glue;
glue = '';
}
if (typeof(pieces) === 'object') {
if (pieces instanceof Array) {
return pieces.join(glue);
}
else {
for (i in pieces) {
retVal += tGlue + pieces[i];
tGlue = glue;
}
return retVal;
}
}
else {
return pieces;
}
}

function print_r(x, max, sep, l) {

l = l || 0;
max = max || 10;
sep = sep || ' ';

if (l > max) {
return "[WARNING: Too much recursion]\n";
}

var
i,
r = '',
t = typeof x,
tab = '';

if (x === null) {
r += "(null)\n";
} else if (t == 'object') {

l++;

for (i = 0; i < l; i++) {
tab += sep;
}

if (x && x.length) {
t = 'array';
}

r += '(' + t + ") :\n";

for (i in x) {
try {
r += tab + '[' + i + '] : ' + print_r(x[i], max, sep, (l + 1));
} catch(e) {
return "[ERROR: " + e + "]\n";
}
}

} else {

if (t == 'string') {
if (x == '') {
x = '(empty)';
}
}

r += '(' + t + ') ' + x + "\n";

}

return r;

};
var_dump = print_r;
[/cc]

Wednesday, December 26, 2007

JS字符截取




Wednesday, March 14, 2007

在一个HTML页面弹出窗口

有时候需要在装载一个HTML页面的时候弹出一个简单的HTML页面窗口,但有不想去新建立一个HTML,可以使用JAVASCRIPT在现有的HTML页面中实现







这样就实现了 ;)

Thursday, March 1, 2007

Javascript 删除确认的方法





在HTML中调用

删 除

Thursday, December 14, 2006

Javascript document.write

对于javascript的初学者来说,document.write 是一个非常实用的函数,它可以把Javascript中的变量等写入到HTML上


JavaScript Cookies

What is a Cookie?
A cookie is a variable that is stored on the visitor's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With JavaScript, you can both create and retrieve cookie values.

Examples of cookies:

  • Name cookie - The first time a visitor arrives to your web page, he or she must fill in her/his name. The name is then stored in a cookie. Next time the visitor arrives at your page, he or she could get a welcome message like "Welcome John Doe!" The name is retrieved from the stored cookie

  • Password cookie - The first time a visitor arrives to your web page, he or she must fill in a password. The password is then stored in a cookie. Next time the visitor arrives at your page, the password is retrieved from the cookie

  • Date cookie - The first time a visitor arrives to your web page, the current date is stored in a cookie. Next time the visitor arrives at your page, he or she could get a message like "Your last visit was on Tuesday August 11, 2005!" The date is retrieved from the stored cookie


Create and Store a Cookie
In this example we will create a cookie that stores the name of a visitor. The first time a visitor arrives to the web page, he or she will be asked to fill in her/his name. The name is then stored in a cookie. The next time the visitor arrives at the same page, he or she will get welcome message.

First, we create a function that stores the name of the visitor in a cookie variable:

function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

The parameters of the function above hold the name of the cookie, the value of the cookie, and the number of days until the cookie expires.

In the function above we first convert the number of days to a valid date, then we add the number of days until the cookie should expire. After that we store the cookie name, cookie value and the expiration date in the document.cookie object.

Then, we create another function that checks if the cookie has been set:

function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{
c_start=c_start + c_name.length+1
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return ""
}

The function above first checks if a cookie is stored at all in the document.cookie object. If the document.cookie object holds some cookies, then check to see if our specific cookie is stored. If our cookie is found, then return the value, if not - return an empty string.

Last, we create the function that displays a welcome message if the cookie is set, and if the cookie is not set it will display a prompt box, asking for the name of the user:

function checkCookie()
{
username=getCookie('username')
if (username!=null && username!="")
{alert('Welcome again '+username+'!')}
else
{
username=prompt('Please enter your name:',"")
if (username!=null && username!="")
{
setCookie('username',username,365)
}
}
}

All together now:

JavaScript的Cookie操作函数


//获得Cookie解码后的值
function GetCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}


//设定Cookie值
function SetCookie(name, value) {
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}


//删除Cookie
function DelCookie(name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}


//获得Cookie的原始值
function GetCookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}

Monday, November 27, 2006

Play Images

复制下面到浏览器的地址栏,回车 ;)
javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.images; DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=Math.sin(R*x1+i*x2+x3)*x4+x5; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++}setInterval('A()',5); void(0);

Wednesday, November 8, 2006

Dojo inlineditbox

ajax昨天白天几乎一天都在学习dojo,用 dojo.weight.inlineeditbox 做了一个工作上的东西,感觉还不错,不过发现需要去学习的真的还有很多,总结了一下 inlineeditbox :