只为唯一 發表於 2023-12-20 00:00:00

dedecms自定义表单用js代替联动类型解决联动问题

<p>
        <span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>最近用DEDECMS完成一个自定义表单,要用到地区的三级级联,地区肯定要使用option下拉框,如果让人一个个填肯定不行,DEDECMS内置的联动类型被注释掉了,网上有解决联动类型的例子,但存在后台信息的是枚举,都是数字,不方便查看,网上的解决方案都不怎么完全,尝试了一下没有成功,自己便采取了比较取巧的方案,用js代替联动类型 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>自定义表单的字段的类型都使用单行文本,设置完之后前台查看,并浏览器查看它的源文件。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>例如: </span></p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="dedecms自定义表单用js代替联动类型解决联动问题" alt="dedecms自定义表单用js代替联动类型解决联动问题" src="https://zhuji.jb51.net/uploads/img/202305/f1b308dd9e49c91ebd648a74c48459da.jpg"><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode4" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        &lt;form action="/plus/diy.php" enctype="multipart/form-data" method="post"&gt; <br>
        &lt;input type="hidden" name="action" value="post" /&gt; <br>
        &lt;input type="hidden" name="diyid" value="1" /&gt; <br>
        &lt;input type="hidden" name="do" value="2" /&gt; <br>
        &lt;table cellpadding="0" cellspacing="1"&gt; <br>
        &lt;tr&gt; <br>
        &lt;td align="right" valign="top"&gt;省份:&lt;/td&gt; <br>
        &lt;td&gt;&lt;input type='text' name='province' id='province' style='width:250px' class='intxt' value='' /&gt; <br>
        &lt;/td&gt; <br>
        &lt;/tr&gt; <br>
        &lt;tr&gt; <br>
        &lt;td align="right" valign="top"&gt;地级市:&lt;/td&gt; <br>
        &lt;td&gt;&lt;input type='text' name='city' id='city' style='width:250px' class='intxt' value='' /&gt; <br>
        &lt;/td&gt; <br>
        &lt;/tr&gt; <br>
        &lt;tr&gt; <br>
        &lt;td align="right" valign="top"&gt;市、县级市:&lt;/td&gt; <br>
        &lt;td&gt;&lt;input type='text' name='country' id='country' style='width:250px' class='intxt' value='' /&gt; <br>
        &lt;/td&gt; <br>
        &lt;/tr&gt; <br>
        &lt;input type="hidden" name="dede_fields" value="province,text;city,text;country,text" /&gt; <br>
        &lt;input type="hidden" name="dede_fieldshash" value="652e45ca2c11e03bbe75d9f5ab1726ba" /&gt;&lt;/table&gt; <br>
        &lt;div align='center' style='height:30px;padding-top:10px;'&gt; <br>
        &lt;input type="submit" name="submit" value="提 交" class='coolbg' /&gt; <br>
        &lt;input type="reset" name="reset" value="重 置" class='coolbg' /&gt; <br>
        &lt;/div&gt; <br>
        &lt;/form&gt; </div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>修改它的form表单,改成自己所需要的样式,并将province,city,country都改成select的类型,三级级联使用js完成 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>如: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode5" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        &lt;form action="/plus/diy.php" enctype="multipart/form-data" method="post"&gt; <br>
        &lt;input type="hidden" name="action" value="post" /&gt; <br>
        &lt;input type="hidden" name="diyid" value="1" /&gt; <br>
        &lt;input type="hidden" name="do" value="2" /&gt; <br>
        &lt;select id="s_province" name="province"&gt;&lt;option value="省份"&gt;省份&lt;/option&gt;&lt;/select&gt; <br>
        &lt;select id="s_city" name="city"&gt;&lt;option value="地级市"&gt;地级市&lt;/option&gt;&lt;/select&gt; <br>
        &lt;select id="s_county" name="country"&gt;&lt;option value="市、县级市"&gt;市、县级市&lt;/option&gt;&lt;/select&gt; <br>
         <br>
         <br>
        &lt;input type="hidden" name="dede_fields" value="province,text;city,text;country,text" /&gt; <br>
        &lt;input type="hidden" name="dede_fieldshash" value="652e45ca2c11e03bbe75d9f5ab1726ba" /&gt;&lt;/table&gt; <br>
        &lt;div align='center' style='height:30px;padding-top:10px;'&gt; <br>
        &lt;input type="submit" name="submit" value="提 交" class='coolbg' /&gt; <br>
        &lt;input type="reset" name="reset" value="重 置" class='coolbg' /&gt; <br>
        &lt;/div&gt; <br>
        &lt;/form&gt; </div>
頁: [1]
查看完整版本: dedecms自定义表单用js代替联动类型解决联动问题