javascriptдcookieµÄһЩ·½·¨
º¯ÊýÒ»¡¢Ð´cookieµÄº¯Êý£¬½«CookieдÈë¿Í»§¶Ë£¬Í¨Óú¯Êý£¬´«Èë3¸ö²ÎÊý¼´¿É£¨CookieÃû×Ö£¬ÖµºÍʧЧÆÚ£©
//º¯Êý£ºÐ´Èëcookie
function WriteCookie (cookieName, cookieValue, expiry)
{
var expDate = new Date();
if(expiry) //Èç¹ûÉèÖÃÁËcookieʧЧʱ¼ä;
{
expDate.setTime (expDate.getTime() expiry);
document.cookie = cookieName "=" escape (cookieValue) "; expires=" expDate.toGMTString();
}
else //ûÓÐÉèÖÃcookieʧЧʱ¼ä;
{
document.cookie = cookieName "=" escape (cookieValue);
}
}
º¯Êý¶þ¡¢È¡µÃ±íµ¥Êý¾Ý
//º¯Êý£ºÈ¡µÃform±íµ¥ÓòµÄÖµ×÷ΪcookieµÄÏà¹ØÖµ£¨cookie name,cookie value,expires£©
function setCookie ()
{
var name = document.myform.text1.value;
var value = document.myform.text2.value;
var num = document.myform.text3.value;
var select = document.myform.text3.selectedIndex;
if (name=="" || value=="" || num==""){
alert ("ÇëÊäÈëCookieµÄÃû×Ö,ÖµºÍʧЧÆÚÔÙ²âÊÔ!");
return false;
}
if(num == 0)
{
WriteCookie(name, value, 0);
}
else if(select == 0)
//Èç¹ûÑ¡ÔñµÄÊÇÌì;ʱ¼ä»»Ëã³ÉÃë;
{
WriteCookie(name, value, 1000 * 60 * 60 * 24 * num);
}
else if(select == 1)
//Èç¹ûÑ¡ÔñµÄÊÇÔÂ;
{
WriteCookie(name, value, 1000 * 60 * 60 * 24 * num * 31);
}
else if(select == 2)
//Èç¹ûÑ¡ÔñµÄÊÇÄê;
{
WriteCookie(name, value, 1000 * 60 * 60 * 24 * num * 365);
}
alert ("CookieÒѾ±£´æ")
}
º¯ÊýÈý¡¢¶ÁcookieµÄÖµ
function ReadCookie (CookieName) {
var CookieString = document.cookie;
var CookieSet = CookieString.split (';');
var SetSize = CookieSet.length;
var CookiePieces
var ReturnValue = "";
var x = 0;
for (x = 0; ((x < SetSize) && (ReturnValue == "")); x ) {
CookiePieces = CookieSet[x].split ('=');
if (CookiePieces[0].substring (0,1) == ' ') {
CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
}
if (CookiePieces[0] == CookieName) {
ReturnValue = CookiePieces[1];
}
}
alert ("Cookie Value is:" ReturnValue);
}
HTML±íµ¥ÄÚÈÝ£º
<form name=myform>
<table width="95%" border="0" cellspacing="0" cellpadding="2">
&
Ïà¹ØÎĵµ£º
ÐÂÖÐ……
1¡¢Êý¾ÝÀàÐÍÑéÖ¤ÎÊÌâ
Asp.NetËäÈ»ÓÐÑéÖ¤¿Ø¼þ£¬µ«ÊÇÓÐЩ¸´ÔÓµÄÑéÖ¤»¹Êǵô«µ½·þÎñÆ÷ÉϽøÐУ¬ÓÃjsËٶȺÍÐÔÄܶ¼±È½ÏºÃ
<script>
//¼ì²éÊÇ·ñΪÈÎÒâÊý£¨ÊµÊý£©
function isNumeric(strNumber) {
var newPar=/^(-|\+)?\d+(\.\d+)?$/
alert(newPar.test(strNumber)); }
//¼ ......
JSON:
[{"subjecttypeId":"1","subjectName":"67","scope":"1",},{"subjecttypeId":"1","subjectName":"345","scope":"1"}]
JavaScript:
var result = window.eval('(' + JSON+ ')');
for(var p in result){
result[p].subjectName;
alert(result[p] ......
ÔÚjavascriptÖеÄstring¶ÔÏóûÓÐtrim·½·¨£¬ËùÒÔtrim¹¦ÄÜÐèÒª×Ô¼ºÊµÏÖ£º
´úÂëÈçÏ£º
Java´úÂë
﹤scriptlanguage=”javascript”﹥
/**
*ɾ³ý×óÓÒÁ½¶ËµÄ¿Õ¸ñ
*/
String.prototype.trim=function(){
&nbs ......
±¾ÎļòÒª½éÉÜJavaScriptÖÐconfirm,alert,promptµÄÓ÷¨,Ï£Íû´ó¼Òѧϰ¹ý³ÌÖÐÄܵõ½Ò»Ð©Æô·¢¡£
window.confirm ²ÎÊý¾ÍÖ»ÓÐÒ»¸ö¡£ÏÔʾÌáʾ¿òµÄÐÅÏ¢¡£°´È·¶¨,·µ»Øtrue£»°´È¡Ïû·µ»Øfalse¡£
< SCRIPT> var bln = window.confirm("È·¶¨Âð?"); alert(bln) < /SCRIPT> window.alert²ÎÊý£¬Ö»ÓÐ ......