dedecms自定義表單用js代替聯(lián)動(dòng)類(lèi)型解決聯(lián)動(dòng)問(wèn)題

字號(hào):


    最近用dedecms完成一個(gè)自定義表單,要用到地區(qū)的三級(jí)級(jí)聯(lián),地區(qū)肯定要使用option下拉框,如果讓人一個(gè)個(gè)填肯定不行,dedecms內(nèi)置的聯(lián)動(dòng)類(lèi)型被注釋掉了,網(wǎng)上有解決聯(lián)動(dòng)類(lèi)型的例子,但存在后臺(tái)信息的是枚舉,都是數(shù)字,不方便查看,網(wǎng)上的解決方案都不怎么完全,嘗試了一下沒(méi)有成功,自己便采取了比較取巧的方案,用js代替聯(lián)動(dòng)類(lèi)型
    自定義表單的字段的類(lèi)型都使用單行文本,設(shè)置完之后前臺(tái)查看,并瀏覽器查看它的源文件。
    例如:
    代碼如下:
    <form action=/plus/diy.php enctype=multipart/form-data method=post>
    <input type=hidden name=action value=post />
    <input type=hidden name=diyid value=1 />
    <input type=hidden name=do value=2 />
    <table style=width:97%; cellpadding=0 cellspacing=1>
    <tr>
    <td align=right valign=top>省份:</td>
    <td><input type='text' name='province' id='province' style='width:250px' class='intxt' value='' />
    </td>
    </tr>
    <tr>
    <td align=right valign=top>地級(jí)市:</td>
    <td><input type='text' name='city' id='city' style='width:250px' class='intxt' value='' />
    </td>
    </tr>
    <tr>
    <td align=right valign=top>市、縣級(jí)市:</td>
    <td><input type='text' name='country' id='country' style='width:250px' class='intxt' value='' />
    </td>
    </tr>
    <input type=hidden name=dede_fields value=province,text;city,text;country,text />
    <input type=hidden name=dede_fieldshash value=652e45ca2c11e03bbe75d9f5ab1726ba /></table>
    <div align='center' style='height:30px;padding-top:10px;'>
    <input type=submit name=submit value=提 交 class='coolbg' />
    <input type=reset name=reset value=重 置 class='coolbg' />
    </div>
    </form>
    修改它的form表單,改成自己所需要的樣式,并將province,city,country都改成select的類(lèi)型,三級(jí)級(jí)聯(lián)使用js完成
    如:
    代碼如下:
    <form action=/plus/diy.php enctype=multipart/form-data method=post>
    <input type=hidden name=action value=post />
    <input type=hidden name=diyid value=1 />
    <input type=hidden name=do value=2 />
    <select id=s_province name=province><option value=省份>省份</option></select>
    <select id=s_city name=city style=margin-left:20px;><option value=地級(jí)市>地級(jí)市</option></select>
    <select id=s_county name=country style=margin-left:20px;><option value=市、縣級(jí)市>市、縣級(jí)市</option></select>
    <script type=text/javascript src=js/area.js></script>
    <script type=text/javascript>_init_area();</script>
    <input type=hidden name=dede_fields value=province,text;city,text;country,text />
    <input type=hidden name=dede_fieldshash value=652e45ca2c11e03bbe75d9f5ab1726ba /></table>
    <div align='center' style='height:30px;padding-top:10px;'>
    <input type=submit name=submit value=提 交 class='coolbg' />
    <input type=reset name=reset value=重 置 class='coolbg' />
    </div>
    </form>