這篇文章主要為大家展示了“javascript經(jīng)典函數(shù)用法有哪些”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“javascript經(jīng)典函數(shù)用法有哪些”這篇文章吧。
10余年的南陵網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。全網(wǎng)整合營(yíng)銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整南陵建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)公司從事“南陵網(wǎng)站設(shè)計(jì)”,“南陵網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
1。字符串替代方法。
function String_Replace(srcString,findString,replaceString){
return String_ReplaceB(srcString, findString, replaceString, 0);
}
function String_ReplaceB(expression, find, replacewith, start) {
var index = expression.indexOf(find, start);
if (index == -1)
return expression;
var findLen = find.length;
var newexp = "";
newexp = expression.substring(0, index)+(replacewith)+(expression.substring(index+findLen));
return String_ReplaceB(newexp, find, replacewith, index+1+findLen);
}
2。取字符串長(zhǎng)度方法
function String_GetLength(str){
var i,rt=0;
for(i=0;i
rt++;
if(str.charCodeAt(i)>256)rt++;
}
return rt;
}
3。求浮點(diǎn)數(shù)方法
function getFloat(num)
{
var num = parseFloat(num);
if(isNaN(num))num = 0;
return num;
}
4。求整數(shù)方法(用到浮點(diǎn)數(shù)取法)
function getInt(num)
{
return parseInt(getFloat(num));
}
5。判斷文本域?qū)ο笫欠裎┛?br/>function at_checkBlank(obj,caption) {
if(String_Replace(obj.value," ","")=="")
{
obj.select();
alert(caption+"不能為空¡");
obj.focus();
return false;
}
return true;
}
6。兩個(gè)Select對(duì)象(llist,rlist)互相操作
var llist = fmObj.AssignedUser;//左邊已經(jīng)選中項(xiàng)目
var rlist = fmObj.WaitedUser;//右邊未被選中的項(xiàng)目
//雙擊右邊select中的項(xiàng)目
function Assignuser() {
if(rlist.selectedIndex < 0 || rlist.selectedIndex > rlist.options.length)return;
var i;
llist.options.length++;
llist.options[llist.options.length-1].value = rlist.options[rlist.selectedIndex].value;
llist.options[llist.options.length-1].text = rlist.options[rlist.selectedIndex].text;
for(i = rlist.selectedIndex; i < rlist.options.length - 1; i ++) {
rlist.options[i].value = rlist.options[i+1].value;
rlist.options[i].text = rlist.options[i+1].text;
}
rlist.length --;
}
//把右邊選中的加入左邊
function AssignRight_AssignSelected(){
for(var i = rlist.length - 1; i >= 0; i --) {
if(rlist.options[i].selected) {
llist.options.length++;
llist.options[llist.options.length-1].value = rlist.options[i].value;
llist.options[llist.options.length-1].text = rlist.options[i].text;
for(var j = i; j < rlist.options.length - 1; j ++) {
rlist.options[j].value = rlist.options[j+1].value;
rlist.options[j].text = rlist.options[j+1].text;
}
rlist.length --;
}
}
}
//把右邊所有加入左邊
function AssignRight_AssignAll(){
for(var i = rlist.length - 1; i >= 0; i --) {
llist.options.length++;
llist.options[llist.options.length-1].value = rlist.options[i].value;
llist.options[llist.options.length-1].text = rlist.options[i].text;
for(var j = i; j < rlist.options.length - 1; j ++) {
rlist.options[j].value = rlist.options[j+1].value;
rlist.options[j].text = rlist.options[j+1].text;
}
rlist.length --;
}
}
//左邊select項(xiàng)目雙擊
function DenyUser() {
if(llist.selectedIndex < 0 || llist.selectedIndex > llist.options.length)return;
var i;
rlist.options.length++;
rlist.options[rlist.options.length-1].value = llist.options[llist.selectedIndex].value;
rlist.options[rlist.options.length-1].text = llist.options[llist.selectedIndex].text;
for(i = llist.selectedIndex; i < llist.options.length - 1; i ++) {
llist.options[i].value = llist.options[i+1].value;
llist.options[i].text = llist.options[i+1].text;
}
llist.length --;
}
//把左邊選中的項(xiàng)目加入右邊
function AssignRight_DenySelected() {
for(var i = llist.length - 1; i >= 0; i --) {
if(llist.options[i].selected) {
rlist.options.length++;
rlist.options[rlist.options.length-1].value = llist.options[i].value;
rlist.options[rlist.options.length-1].text = llist.options[i].text;
for(j = llist.selectedIndex; j < llist.options.length - 1; j ++) {
llist.options[j].value = llist.options[j+1].value;
llist.options[j].text = llist.options[j+1].text;
}
llist.length --;
}
}
}
//左邊所有項(xiàng)目加入右邊
function AssignRight_DenyAll() {
for(var i = llist.length - 1; i >= 0; i --) {
rlist.options.length++;
rlist.options[rlist.options.length-1].value = llist.options[i].value;
rlist.options[rlist.options.length-1].text = llist.options[i].text;
for(j = i; j < llist.options.length - 1; j ++) {
llist.options[j].value = llist.options[j+1].value;
llist.options[j].text = llist.options[j+1].text;
}
llist.length --;
}
}
以上是“javascript經(jīng)典函數(shù)用法有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!