锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
for (var i = 0; i < this.length; i++) {
if (this[i] === value) {
return true;
}
}
return false;
};
Array.prototype.max = function(){
for (var i = 1, max = this[0]; i < this.length; i++){
if (max < this[i]) {
max = this[i];
}
return max;
};
Array.prototype.min = function(){
for (var i = 1, min = this[0]; i < this.length; i++){
if (min > this[i]) {
min = this[i];
}
return min;
};
Array.prototype.indexOf = function(p_var)
{
for (var i=0; i<this.length; i++)
{
if (this[i] == p_var)
{
return(i);
}
}
return(-1);
}
Array.prototype.exists = function(p_var) {return(this.indexOf(p_var) != -1);}
Array.prototype.queue = function(p_var) {this.push(p_var)}
Array.prototype.dequeue = function() {return(this.shift());}
Array.prototype.removeAt = function(p_iIndex) {return this.splice(p_iIndex, 1);}
Array.prototype.remove = function(o)
{
var i = this.indexOf(o);
if (i>-1)
{
this.splice(i,1);
}
return (i>-1);
}
Array.prototype.clear = function()
{
var iLength = this.length;
for (var i=0; i < iLength; i++)
{
this.shift();
}
}
Array.prototype.addArray = function(p_a)
{
if (p_a)
{
for (var i=0; i < p_a.length; i++)
{
this.push(p_a[i]);
}
}
}
Array.prototype.Unique = function()
{
var a = {}; for(var i=0; i<this.length; i++)
{
if(typeof a[this[i]] == "undefined")
a[this[i]] = 1;
}
this.length = 0;
for(var i in a)
this[this.length] = i;
return this;
};
Array.prototype.indexOf = function(obj, fromIndex)
{
if (fromIndex == null)
{
fromIndex = 0;
}
else if (fromIndex < 0)
{
fromIndex = Math.max(0, this.length + fromIndex);
}
for (var i = fromIndex; i < this.length; i++)
{
if (this[i] === obj)
{
return i;
}
}
return-1;
};
Array.prototype.lastIndexOf = function(obj, fromIndex)
{
if (fromIndex == null)
{
fromIndex = this.length - 1;
}
else if (fromIndex < 0)
{
fromIndex=Math.max(0, this.length+fromIndex);
}
for (var i = fromIndex; i >= 0; i--)
{
if (this[i] === obj)
{
return i;
}
}
return -1;
};
Array.prototype.insertAt = function(o, i)
{
this.splice(i, 0, o);
};
Array.prototype.insertBefore = function(o, o2)
{
var i = this.indexOf(o2);
if (i == -1)
{
this.push(o);
}
else
{
this.splice(i, 0, o);
}
};
Array.prototype.remove = function(o)
{
var i = this.indexOf(o);
if (i != -1)
{
this.splice(i, 1);
}
};
Array.prototype.mm=function()
{
var a={}, m=0, n="";
for(var i=0; i<this.length; i++)
a[this[i]]?++a[this[i]]:a[this[i]]=1;
for(i in a){m=Math.max(m, a[i]); if(m==a[i]) n=i;}
return {"variable": n, "times": m};
]]>
<form id="f">
<select size="1" name="s">
<option value="lizi.name">姊ㄥ瓙闈㈤</option>
<option value="baidu.com">鐧懼害</option>
</select>
</form>
---------------------------------------------------------------------------
<script type="text/javascript">
<!--
var f = document.getElementById("f");
//鑾峰緱select鍒楄〃欏規(guī)暟鐩?
document.write(f.s.options.length);
document.write(f.s.length);
//褰撳墠閫変腑欏圭殑涓嬫爣(浠? 寮濮?錛堟湁涓ょ鏂規(guī)硶錛?
//濡傛灉閫夋嫨浜嗗欏癸紝鍒欒繑鍥炵涓涓変腑欏圭殑涓嬫爣
document.write(f.s.options.selectedIndex);
document.write(f.s.selectedIndex);
//媯嫻嬫煇涓欏規(guī)槸鍚﹁閫変腑
document.write(f.s.options[0].selected);
//鑾峰緱鏌愪竴欏圭殑鍊煎拰鏂囧瓧
document.write(f.s.options[0].value);
document.write(f.s.options[1].text);
//鍒犻櫎鏌愪竴欏?
f.s.options[1] = null;
//榪藉姞涓欏?
f.s.options[f.s.options.length] = new Option("榪藉姞鐨則ext", "榪藉姞鐨剉alue");
//鏇存敼涓欏?
f.s.options[1] = new Option("鏇存敼鐨則ext", "鏇存敼鐨剉alue");
//涔熷彲浠ョ洿鎺ヨ緗欏圭殑 text 鍜?value
//-->
</script>
//鍏ㄩ夊垪琛ㄤ腑鐨勯」
function SelectAllOption(list)
{
for (var i=0; i<list.options.length; i++)
{
list.options[i].selected = true;
}
}
//鍙嶉夊垪琛ㄤ腑鐨勯」
function DeSelectOptions(list)
{
for (var i=0; i<list.options.length; i++)
{
list.options[i].selected = !list.options[i].selected;
}
}
//榪斿洖鍒楄〃涓夋嫨欏規(guī)暟鐩?
function GetSelectedOptionsCnt(list)
{
var cnt = 0;
var i = 0;
for (i=0; i<list.options.length; i++)
{
if (list.options[i].selected)
{
cnt++;
}
}
return cnt;
}
//娓呯┖鍒楄〃
function ClearList(list)
{
while (list.options.length > 0)
{
list.options[0] = null;
}
}
//鍒犻櫎鍒楄〃閫変腑欏?
//榪斿洖鍒犻櫎欏圭殑鏁伴噺
function DelSelectedOptions(list)
{
var i = 0;
var deletedCnt = 0;
while (i < list.options.length)
{
if (list.options[i].selected)
{
list.options[i] = null;
deletedCnt++;
}
else
{
i++;
}
}
return deletedCnt;
}
//姝ゅ嚱鏁版煡鎵劇浉搴旂殑欏規(guī)槸鍚﹀瓨鍦?
//repeatCheck鏄惁榪涜閲嶅鎬ф鏌?
//鑻ヤ負(fù)"v"錛屾寜鍊艱繘琛岄噸澶嶅兼鏌?
//鑻ヤ負(fù)"t"錛屾寜鏂囧瓧榪涜閲嶅鍊兼鏌?
//鑻ヤ負(fù)"vt"錛屾寜鍊煎拰鏂囧瓧榪涜閲嶅鍊兼鏌?
//鍏跺畠鍊鹼紝涓嶈繘琛岄噸澶嶆ф鏌ワ紝榪斿洖false
function OptionExists(list, optText, optValue, repeatCheck)
{
var i = 0;
var find = false;
if (repeatCheck == "v")
{
//鎸夊艱繘琛岄噸澶嶅兼鏌?
for (i=0; i<list.options.length; i++)
{
if (list.options[i].value == optValue)
{
find = true;
break;
}
}
}
else if (repeatCheck == "t")
{
//鎸夋枃瀛楄繘琛岄噸澶嶆鏌?
for (i=0; i<list.options.length; i++)
{
if (list.options[i].text == optText)
{
find = true;
break;
}
}
}
else if (repeatCheck == "vt")
{
//鎸夊煎拰鏂囧瓧榪涜閲嶅媯鏌?
for (i=0; i<list.options.length; i++)
{
if ((list.options[i].value == optValue) && (list.options[i].text ==
optText))
{
find = true;
break;
}
}
}
return find;
}
//鍚戝垪琛ㄤ腑榪藉姞涓涓」
//list 鏄榪藉姞鐨勫垪琛?
//optText 鍜?optValue 鍒嗗埆琛ㄧず欏圭殑鏂囧瓧鍜屽?
//repeatCheck 鏄惁榪涜閲嶅鎬ф鏌ワ紝鍙傝 OptionExists
//娣誨姞鎴愬姛榪斿洖 true錛屽け璐ヨ繑鍥?false
function AppendOption(list, optText, optValue, repeatCheck)
{
if (!OptionExists(list, optText, optValue, repeatCheck))
{
list.options[list.options.length] = new Option(optText, optValue);
return true;
}
else
{
return false;
}
}
//鎻掑叆欏?
//index 鎻掑叆浣嶇疆錛屽綋鎻掑叆浣嶇疆 >= 鍒楄〃鐜版湁欏規(guī)暟閲忔椂錛屽叾浣滅敤鐩稿綋浜庝笉榪涜閲嶅媯
鏌ョ殑榪藉姞欏?
//optText 鍜?optValue 鍒嗗埆琛ㄧず欏圭殑鏂囧瓧鍜屽?
function InsertOption(list, index, optText, optValue)
{
var i = 0;
for (i=list.options.length; i>index; i--)
{
list.options[i] = new Option(list.options[i-1].text, list.options[i-
1].value);
}
list.options[index] = new Option(optText, optValue);
}
//灝嗕竴涓垪琛ㄤ腑鐨勯」瀵煎埌鍙︿竴涓垪琛ㄤ腑
//repeatCheck鏄惁榪涜閲嶅鎬ф鏌ワ紝鍙傝OptionExists
//deleteSource欏瑰鍒扮洰鏍囧悗錛屾槸鍚﹀垹闄ゆ簮鍒楄〃涓殑欏?
//榪斿洖褰卞搷鐨勯」鏁伴噺
function ListToList(sList, dList, repeatCheck, deleteSource)
{
//鎵褰卞搷鐨勮鏁?
var lines = 0;
var i = 0;
while (i<sList.options.length)
{
if (sList.options[i].selected && AppendOption(dList, sList.options[i].text,
sList.options[i].value, repeatCheck))
{
//娣誨姞鎴愬姛
lines++;
if (deleteSource)
{
//鍒犻櫎婧愬垪琛ㄤ腑鐨勯」
sList.options[i] = null;
}
else
{
i++;
}
}
else
{
i++;
}
}
return lines;
}
//鍒楄〃涓変腑欏逛笂縐?
function MoveSelectedOptionsUp(list)
{
var i = 0;
var value = "";
var text = "";
for (i=0; i<(list.options.length-1); i++)
{
if (!list.options[i].selected && list.options[i+1].selected)
{
value = list.options[i].value;
text = list.options[i].text;
list.options[i] = new Option(list.options[i+1].text, list.options
[i+1].value);
list.options[i].selected = true;
list.options[i+1] = new Option(text, value);
}
}
}
//鍒楄〃涓変腑欏逛笅縐?
function MoveSelectedOptionsDown(list)
{
var i = 0;
var value = "";
var text = "";
for (i=list.options.length-1; i>0; i--)
{
if (!list.options[i].selected && list.options[i-1].selected)
{
value = list.options[i].value;
text = list.options[i].text;
list.options[i] = new Option(list.options[i-1].text, list.options[i-
1].value);
list.options[i].selected = true;
list.options[i-1] = new Option(text, value);
}
}
}
//鏄惁鍚堟硶鐨勬棩鏈燂紵month 鍩轟簬0
function __isLegalDate(year,month,day)
{
聽聽聽聽 if(year < 1900 || year > 3000)
聽聽聽聽 {
聽聽聽聽 聽sError = "騫翠喚閿欒";
聽聽聽聽 聽return false;
聽聽聽聽 }
//聽聽聽聽 if(month < 0 || month > 12)
聽 if(month <= 0 || month > 12)
聽聽聽聽 {
聽聽聽聽 聽sError = "鏈堜喚涓嶈兘灝忎簬1錛屼篃涓嶈兘澶т簬12";
聽聽聽聽 聽return false;
聽聽聽聽 }
聽聽聽聽 if(day < 1)
聽聽聽聽 {
聽聽聽聽 聽sError = "鏃ユ湡涓嶈兘灝忎簬1";
聽聽聽聽 聽return false;
聽聽聽聽 }
聽聽聽聽 if (day > 31)
聽聽聽聽 {
聽聽聽聽 聽sError = "鏃ユ湡涓嶈兘澶т簬31";
聽聽聽聽 聽return false;
聽聽聽聽 }
聽聽聽聽 if(month == 2)
聽聽聽聽 {
聽聽聽聽 聽if( __isLeapYear(year)聽 )
聽聽聽聽 聽{
聽聽聽聽聽聽聽 聽if(day > 29)
聽聽聽聽聽聽聽 聽{
聽聽聽聽聽聽聽聽 聽聽sError = "闂板勾錛?鏈堜喚鏃ユ湡涓嶈兘澶т簬29";
聽聽聽聽聽聽聽聽 聽聽return false;
聽聽聽聽聽聽聽聽 聽}
聽聽}
聽聽else
聽聽{
聽聽聽if(day > 28)
聽聽聽{
聽聽聽聽sError = "闈為棸騫達(dá)紝2鏈堜喚鏃ユ湡涓嶈兘澶т簬28";
聽聽聽聽return false;
聽聽聽}
聽聽}
聽} else
聽{
聽聽var d1, m1=month;
聽聽if(m1 > 7)
聽聽聽m1 = m1 + 1;
聽聽d1 = 30 + m1 % 2;
聽聽if(day > d1)
聽聽{
聽聽聽sError = "璇ユ湀鏃ユ湡涓嶈兘澶т簬" + d1 +"澶?;
聽聽聽return false;
聽聽}
聽}
聽return true;
}
//鏄惁鍚堟硶鐨勬湀錛?br />聽
function __isLegalMonth(year,month)
{
聽聽聽聽 if(year < 1900 || year > 3000)
聽聽聽聽 {
聽聽聽聽 聽sError = "騫翠喚閿欒";
聽聽聽聽 聽return false;
聽聽聽聽 }
聽 //if(month < 0 || month > 12)聽 //鍘熸潵鏉′歡濡傛灉鏄?00400鍒欏垽鏂笉鍑洪敊璇?br />聽 if(month < 0 || month > 12 || month=="00"|| month=="0") //鏀規(guī)涓婇潰鐨勯敊璇?br />聽聽聽聽 {
聽聽聽聽 聽sError = "鏈堜喚涓嶈兘灝忎簬1錛屼篃涓嶈兘澶т簬12";
聽聽聽聽 聽return false;
聽聽聽聽 }
聽return true;
}
//鏄惁鍚堟硶鐨勫勾錛?br />function __isLegalYear(year)
{
聽聽聽聽 if(year < 1900 || year > 3000)
聽聽聽聽 {
聽聽聽聽 聽sError = "騫翠喚閿欒";
聽聽聽聽 聽return false;
聽聽聽聽 }
聽return true;
}
//鏄惁涓哄悎娉曟椂闂?br />function __isLegalTime(hour, minute, second)
{
聽聽聽聽 if(hour < 0 || hour > 23)
聽聽聽聽 {
聽聽聽聽 聽sError = "鏃墮挓閿欒";
聽聽聽聽 聽return false;
聽聽聽聽 }
聽聽聽聽 if(minute < 0 || minute > 59)
聽聽聽聽 {
聽聽聽聽 聽sError = "鍒嗛挓閿欒";
聽聽聽聽 聽return false;
聽聽聽聽 }
聽聽聽聽 if (second < 0 || second > 59)
聽聽聽聽 {
聽聽聽聽 聽sError = "縐掗挓閿欒";
聽聽聽聽 聽return false;
聽聽聽聽 }
聽return true;
}
//鍒ゅ畾鏄惁涓烘暟瀛?br />function __isNum(s)
{
聽var re = /^[0-9]+$/;
聽return re.test(s);
}
//鏃跺欎負(fù)嫻偣鏁?br />function __isFloat(s)
{
聽if (__isNum(s)) return true;
聽var re = /^[+|-]{0,1}\d*\.\d+$/;
聽return re.test(s);
}
function _isEFloat(s)
{
聽聽聽 var re = /^[+|-]{0,1}\d*\.[\.\d+]{0,1}\e[-|+]{0,1}\d+$/;
聽聽聽 return re.test(s);
}
function __isQuoteIn(s)
{
聽var re = /\"|\'|\鈥渱\鈥潀\鈥榺\鈥?;
聽return re.test(s);
}
//寰楀埌褰撳墠鏃墮棿
function getCurrentDate()
{
聽var date = new Date();
聽var year = ""+date.getFullYear();
聽var month = date.getMonth()+1;
聽if(month<10){ month="0"+month;}
聽var day = date.getDate();
聽if(day<10){ day = "0"+day;}
聽return year+month+day;
}
聽
//鑷畾涔夊嚱鏁?br />//鍙栧緱瀛楃涓詫紝鍘繪帀鍓嶅悗鐨勭┖鏍?br />function Trim(str)聽聽聽聽聽聽
{聽聽聽
聽return str.replace(/(^\s*)|(\s*$)/g,"");
}
//鍒ゆ柇瀛楃涓叉槸鍚︿負(fù)絀?br />function isNull(str)聽聽聽聽
{
聽if (str == null || Trim(str) == "")
聽聽return true;
聽return false;
}
//鍒ゆ柇瀛楃涓叉槸鍚︿負(fù)鏁存暟
function isInt(str)聽聽聽
{
聽聽聽 if(Trim(str) == "0")
聽聽聽聽 return false;聽
聽var ch = str.substring(0,1);
聽if (ch == "0" && Trim(str) != "0")
聽聽return false;
聽for (var i=0; i<str.length ; i++)
聽{
聽聽var s = str.substring(i, i+1);
聽聽if (!(s >= "0" && s <="9"))
聽聽{
聽聽聽return true;
聽聽聽break;
聽聽}
聽}
聽return false;
}
//鍒ゆ柇鏄惁鏄誕鐐規(guī)暟
function isFloat(strTest){
var reg;
reg=/^\+?(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
var r=strTest.match(reg);
聽 if(strTest=='0'){
聽 聽return true;
聽 聽}else if(r==null){
聽//alert("no float data");
聽聽聽聽聽聽聽 return false;
聽聽聽 }else{
聽聽//alert(strTest + " is a float data");
聽聽聽聽聽聽聽 return true;聽聽聽聽
聽聽聽 }
聽 }
//鍒ゆ柇鏄惁鏄鏁存暟
function myIsInt(strTest){
var reg;
//reg=/^\+?[0-9]*[0-9][0-9]*$/;
reg=/^\+?[0-9]*[1-9][0-9]*$/;
var r=strTest.match(reg);
聽 if(r==null){
聽//alert("no float data");
聽聽聽聽聽聽聽 return false;
聽聽聽 }else{
聽聽//alert(strTest + " is a float data");
聽聽聽聽聽聽聽 return true;聽聽聽聽
聽聽聽 }
聽 }