<!--
//選擇地區(qū)的二級(jí)分類(lèi)(非通用調(diào)用)
function selNext(oj, v)
{
var newobj = oj.options;
var selv = parseInt(v);
var maxv = parseInt(v) + 500;
while(newobj.length > 0) {
oj.remove(0);
}
clear(oj);
if(selv==0)
{
aOption = document.createElement('OPTION');
aOption.text = '具體地區(qū)';
aOption.value = '0';
oj.options.add(aOption);
return;
}
else
{
aOption = document.createElement('OPTION');
aOption.text = '具體地區(qū)';
aOption.value = '0';
oj.options.add(aOption);
}
var str = '';
for(i=selv+1; i < maxv; i++)
{
if(!em_nativeplaces[i]) continue;
aOption = document.createElement('OPTION');
aOption.text = em_nativeplaces[i];
aOption.value = i;
oj.options.add(aOption);
}
}
//子類(lèi)改變事件
function ChangeSon()
{
/*
var emname = this.name.replace('_son', '');
var topSelObj = document.getElementById(emname+'_top');
if(this.options[this.selectedIndex].value==0) {
document.getElementById('hidden_'+emname).value = topSelObj.options[topSelObj.selectedIndex].value;
}
else {
document.getElementById('hidden_'+emname).value = this.options[this.selectedIndex].value;
}
*/
// 由于支持3級(jí)聯(lián)動(dòng),所以這里需要對(duì)自己改變進(jìn)行重構(gòu)
var emname = this.name.replace('_son', '');
// alert(emname);
if( document.getElementById(idname+'_sec') )
{
var oj = document.getElementById(idname + '_sec');
}
else
{
var oj = document.createElement('select');
oj.name = emname + '_sec';
oj.id = idname + '_sec';
oj.onchange = ChangeSec;
}
var v = this.options[this.selectedIndex].value;
document.getElementById('hidden_'+idname).value = v;
var newobj = oj.options;
var selarr = eval('em_'+emname+'s');
var selv = parseInt(v);
var maxv = parseInt(v) + 0.5;
// alert(maxv);
i = 0;
while(newobj && newobj.length > 0) oj.remove(0);
clear(oj);
if(selv == 0)
{
aOption = document.createElement('OPTION');
aOption.text = '請(qǐng)選擇..';
aOption.value = '0';
oj.options.add(aOption);
return;
}
else
{
aOption = document.createElement('OPTION');
aOption.text = '請(qǐng)選擇..';
aOption.value = '0';
oj.options.add(aOption);
}
var str = '';
var j=0;
for(i = selv + 0.001; i < maxv; i = FloatAdd(i, 0.001))
{
if(!selarr[i]) continue;
aOption = document.createElement('OPTION');
aOption.text = selarr[i];
aOption.value = i;
oj.options.add(aOption);
j++;
}
if(j > 0) document.getElementById('span_'+idname+'_sec').appendChild(oj);
else document.getElementById('span_'+idname+'_sec').innerHTML = "";
}
// 改變第三級(jí)的事件
function ChangeSec()
{
var emname = this.name.replace('_sec', '');
var topSelObj = document.getElementById(idname+'_top');
if(this.options[this.selectedIndex].value==0) {
document.getElementById('hidden_'+idname).value = topSelObj.options[topSelObj.selectedIndex].value;
}
else {
document.getElementById('hidden_'+idname).value = this.options[this.selectedIndex].value;
}
}
//頂級(jí)類(lèi)改變事件
function selNextSon()
{
var emname = this.name.replace('_top', '');
var idname = this.id.replace('_top', '');
if( document.getElementById(idname+'_son') )
{
var oj = document.getElementById(idname + '_son');
}
else
{
var oj = document.createElement('select');
oj.name = emname + '_son';
oj.id = idname + '_son';
oj.onchange = ChangeSon;
}
var v = this.options[this.selectedIndex].value;
document.getElementById('hidden_'+idname).value = v;
var newobj = oj.options;
var selarr = eval('em_'+emname+'s');
var selv = parseInt(v);
var maxv = parseInt(v) + 500;
while(newobj && newobj.length > 0) oj.remove(0);
clear(oj);
if(selv==0)
{
aOption = document.createElement('OPTION');
aOption.text = '請(qǐng)選擇..';
aOption.value = '0';
oj.options.add(aOption);
return;
}
else
{
aOption = document.createElement('OPTION');
aOption.text = '請(qǐng)選擇..';
aOption.value = '0';
oj.options.add(aOption);
}
var str = '';
for(i=selv+1; i < maxv; i++)
{
if(!selarr[i]) continue;
aOption = document.createElement('OPTION');
aOption.text = selarr[i];
aOption.value = i;
oj.options.add(aOption);
}
document.getElementById('span_'+idname+'_son').appendChild(oj);
}
// 根據(jù)數(shù)組生成多級(jí)聯(lián)動(dòng)菜單
function MakeTopSelect(emname,idname, selvalue)
{
var selectFormHtml = '';
var aOption = null;
var selObj = document.createElement("select");
selObj.name = emname + '_top';
selObj.id = idname + '_top';
selObj.onchange = selNextSon;
var selarr = eval('em_'+emname+'s');
// alert(selarr[1002.2]);
var topvalue = 0;
var sonvalue = 0;
var secvalue = 0;
aOption = document.createElement('OPTION');
aOption.text = '請(qǐng)選擇..';
aOption.value = 0;
selObj.options.add(aOption);
// alert(selvalue);
if(selvalue % 500 == 0 )
{
topvalue = selvalue;
}
// 如果是小數(shù),則依次取出頂級(jí)數(shù)值,二級(jí)數(shù)值以及三級(jí)數(shù)值
else if(!!(selvalue % 1))
{
secvalue = selvalue;
sonvalue = Math.floor(selvalue);
topvalue = sonvalue - (sonvalue % 500);
// alert(secvalue);
}
else {
sonvalue = selvalue;
topvalue = selvalue - (selvalue % 500);
}
for(i = 500; i <= selarr.length; i += 500)
{
if(!selarr[i]) continue;
aOption = document.createElement('OPTION');
if(i == topvalue) {
aOption = document.createElement('OPTION');
aOption.text = selarr[i];
aOption.value = i;
selObj.options.add(aOption);
aOption.selected = true;
}
else {
aOption = document.createElement('OPTION');
aOption.text = selarr[i];
aOption.value = i;
selObj.options.add(aOption);
}
}
document.getElementById('span_'+idname).appendChild(selObj);
//如果子類(lèi)存在值,創(chuàng)建子類(lèi)
//if(sonvalue > 0 || topvalue > 0) {
selObj = document.createElement("select");
selObj.name = emname + '_son';
selObj.id = idname + '_son';
selObj.onchange = ChangeSon;
aOption = document.createElement('OPTION');
aOption.text = '請(qǐng)選擇..';
aOption.value = 0;
selObj.options.add(aOption);
//當(dāng)大類(lèi)有值輸出子類(lèi)
if(topvalue > 0)
{
var selv = topvalue;
var maxv = parseInt(topvalue) + 500;
for(i = selv + 1; i < maxv; i++)
{
if(!selarr[i]) continue;
aOption = document.createElement('OPTION');
if(i == sonvalue) {
aOption = document.createElement('OPTION');
aOption.text = selarr[i];
aOption.value = i;
selObj.options.add(aOption);
aOption.selected = true;
}
else {
aOption = document.createElement('OPTION');
aOption.text = selarr[i];
aOption.value = i;
selObj.options.add(aOption);
}
}
}
document.getElementById('span_'+idname+'_son').appendChild(selObj);
// 若存在第三級(jí)則創(chuàng)建
if(secvalue > 0)
{
selObj = document.createElement("select");
selObj.name = emname + '_sec';
selObj.id = idname + '_sec';
selObj.onchange = ChangeSec;
aOption = document.createElement('OPTION');
aOption.text = '請(qǐng)選擇..';
aOption.value = 0;
selObj.options.add(aOption);
var selv = sonvalue;
var maxv = parseInt(sonvalue) + 0.5;
// alert(maxv);
i = 0;
for(i = selv + 0.001; i < maxv; i = FloatAdd(i, 0.001))
{
if(!selarr[i]) continue;
aOption = document.createElement('OPTION');
if(i == secvalue) {
aOption = document.createElement('OPTION');
aOption.text = selarr[i];
aOption.value = i;
selObj.options.add(aOption);
aOption.selected = true;
}
else {
aOption = document.createElement('OPTION');
aOption.text = selarr[i];
aOption.value = i;
selObj.options.add(aOption);
}
}
}
document.getElementById('span_'+idname+'_sec').appendChild(selObj);
}
// 兩個(gè)小數(shù)相加進(jìn)度計(jì)算
function FloatAdd(arg1, arg2)
{
var r1,r2,m;
try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
m=Math.pow(10,Math.max(r1,r2))
return (arg1*m+arg2*m)/m
}
//清除舊對(duì)象
function clear(o)
{
l=o.length;
for (i = 0; i< l; i++){
o.options[1]=null;
}
}
-->
將上面代碼保存為新的js文件,注意不要覆蓋官方原來(lái)的,否則可能因?yàn)楹罄m(xù)的多級(jí)聯(lián)動(dòng)菜單添加而反復(fù)修改文件
<script language="javascript" type="text/javascript" src="你自定義的js文件目錄"></script>
這句不多說(shuō)
注意在頁(yè)面的運(yùn)行腳本中,原來(lái)的兩個(gè)參數(shù)改成了三個(gè),第一個(gè)是聯(lián)動(dòng)類(lèi)型的英文名稱(chēng),具體請(qǐng)?jiān)诤笈_(tái)查看
第二個(gè)參數(shù)是你自定義的id,防止頁(yè)面上出現(xiàn)重復(fù)id的現(xiàn)象,第三個(gè)參數(shù)是初始選項(xiàng)
<script language="javascript" type="text/javascript">MakeTopSelect("MyArea","IdName", 0);</script>
版權(quán)聲明: 本站資源均來(lái)自互聯(lián)網(wǎng)或會(huì)員發(fā)布,如果侵犯了您的權(quán)益請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除!謝謝!
轉(zhuǎn)載請(qǐng)注明: 織夢(mèng)DEDECMS 同一頁(yè)面調(diào)用多個(gè)相同的js聯(lián)動(dòng)菜單