v2studio 發表於 2025-10-13 10:48:45

Discuz! 前端 JS 常用函数解释

<br /><font size="4"><font color="DarkRed"><strong>showMenu() 显示弹出菜单</strong></font></font><br />参数 v 数组格式:{'key1':'value1', 'key2':'value2', 'key3':'value3'}<br />参数如下:<br /><table cellspacing="0" class="t_table" ><tr><td width="110"><strong>key</strong></td><td width="190"><strong>默认值</strong></td><td width="230"><strong>含义</strong></td><td><strong>可选值及解释</strong></td></tr><tr><td>ctrlid</td><td>(必填)</td><td>控制菜单的 id</td><td><br /></td></tr><tr><td>showid</td><td>ctrlid</td><td>弹出菜单的 id</td><td><br /></td></tr><tr><td>menuid</td><td>showid + '_menu'</td><td>显示菜单的 id</td><td><br /></td></tr><tr><td>evt</td><td>'mouseover'</td><td>响应函数的事件</td><td>click: ctrlObj 的 onclick 触发&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />mouseover: ctrlObj 的 onmouseover 触发&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td></tr><tr><td>pos</td><td>'43'</td><td>菜单位置</td><td>详见 setMenuPosition() 中对 pos 的解释</td></tr><tr><td>layer</td><td>1</td><td>菜单层级</td><td>大于 0 的任意整数</td></tr><tr><td>duration</td><td>2</td><td>菜单显示方式</td><td>3:菜单一直显示,除非执行 hideMenu(),或者页面 unload&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />2:鼠标移开 ctrlObj 及 menuObj 即开始计时 timeout 毫秒后消失&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />1:鼠标移开 ctrlObj 即开始计时 timeout 毫秒后消失&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />0:菜单显示即开始计时 timeout 毫秒后消失&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td></tr><tr><td>timeout</td><td>250</td><td>菜单持续时间</td><td>单位:毫秒</td></tr><tr><td>mtype</td><td>'menu'</td><td>菜单类型</td><td>menu:普通菜单&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />win:浮窗&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />prompt:提示信息&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />dialog:对话框&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td></tr><tr><td>maxh</td><td>600</td><td>菜单最大高度,实际高度超过 maxh 时菜单将出现垂直滚动条</td><td><br /></td></tr><tr><td>cache</td><td>1</td><td>是否缓存菜单</td><td>1:是&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />0:否&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br /></td></tr><tr><td>drag</td><td><br /></td><td>拖拽菜单对象的 id,如果希望整个菜单都可以拖拽 请设置 drag 等于1</td><td><br /></td></tr><tr><td>fade</td><td>0</td><td>淡入淡出效果</td><td>1:是&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />0:否&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br /></td></tr><tr><td>cover</td><td>0</td><td>是否显示一个遮罩覆盖整个页面</td><td>1:是&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />0:否&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td></tr><tr><td>zindex</td><td>JSMENU['zIndex']['menu']</td><td>菜单层叠顺序</td><td><br /></td></tr><tr><td>ctrlclass</td><td><br /></td><td>控制对象在菜单弹出后的 class 值,duration = 2 时有效</td><td><br />onmouseover=&quot;showMenu(this.id)&quot;<br /><br /><font size="4"><br /><font color="DarkRed"><strong>ajaxmenu() AJAX/GET请求 显示弹出菜单</strong><br /><strong>ajaxmenu(ctrlObj, timeout, cache, duration, pos, recall, idclass, contentclass)</strong></font></font><br />参数如下:&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <table cellspacing="0" class="t_table" ><tr><td width="110"><strong>key</strong></td><td width="190"><strong>默认值</strong></td><td width="230"><strong>含义</strong></td><td><strong>可选值及解释</strong></td></tr><tr><td>ctrlObj</td><td>(必填)</td><td>控制菜单的对象</td><td><br /></td></tr><tr><td>timeout</td><td>3000</td><td>菜单持续时间</td><td><br /></td></tr><tr><td>cache</td><td>1</td><td>是否缓存菜单</td><td>1:是&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />0:否&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br /></td></tr><tr><td>duration</td><td>0 (timeout = 0 时为 3)</td><td>菜单显示方式</td><td>3:菜单一直显示,除非执行 hideMenu(),或者页面 unload&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />2:鼠标移开 ctrlObj 及 menuObj 即开始计时 timeout 毫秒后消失&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />1:鼠标移开 ctrlObj 即开始计时 timeout 毫秒后消失&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />0:菜单显示即开始计时 timeout 毫秒后消失&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td></tr><tr><td>pos</td><td>'43'</td><td>菜单位置</td><td>详见 setMenuPosition() 中对 pos 的解释</td></tr><tr><td>recall</td><td><br /></td><td>信息返回后执行的代码</td><td><br /></td></tr><tr><td>idclass</td><td>'p_pop'</td><td>菜单的 class 属性值</td><td><br /></td></tr><tr><td>contentclass</td><td>'p_opt'</td><td>菜单内容的 class 属性值</td><td><br /><br /><font size="4"><font color="DarkRed"><br /><strong>setMenuPosition() 菜单定位</strong><br /><strong>setMenuPosition(showid, menuid, pos)</strong></font></font><br />参数如下:<br /><table cellspacing="0" class="t_table" ><tr><td width="110"><strong>key</strong></td><td width="190"><strong>默认值</strong></td><td width="230"><strong>含义</strong></td><td><strong>可选值及解释</strong></td></tr><tr><td>showid</td><td>(必填)</td><td>弹出菜单的 id</td><td><br /></td></tr><tr><td>menuid</td><td>(必填)</td><td>菜单 id</td><td><br /></td></tr><tr><td>pos</td><td>'43'</td><td>菜单弹出位置及方向,必须是字串类型格式&quot;BD&quot;,B 为基点 D 为方向。方向设定后,函数会根据实际弹出的位置及浏览器窗口大小进行二次调整,取消二次调整请以&quot;!&quot;结尾表示强制</td><td>BD:自定义&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />B:&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;D:&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />1:左上角&nbsp;&nbsp;1:左上方&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />2:右上角&nbsp;&nbsp;2:右上方&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />3:右下角&nbsp;&nbsp;3:右下方&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />4:左下角&nbsp;&nbsp;4:左下方&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />00: 屏幕居中 不需要设置位置&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;id=&quot;userpop_$value&quot;<br /><br /><br /><font size="4"><font color="DarkRed"><strong>showDialog() 显示对话框</strong><br /><strong>showDialog(msg, mode, t, func, cover, funccancel, leftmsg, confirmtxt, canceltxt, closetime, locationtime)</strong></font></font><br />参数如下:<br /><table cellspacing="0" class="t_table" ><tr><td width="110"><strong>key</strong></td><td width="190"><strong>默认值</strong></td><td width="230"><strong>含义</strong></td><td><strong>可选值及解释</strong></td></tr><tr><td>msg</td><td>(必填)</td><td>提示信息内容</td><td><br /></td></tr><tr><td>mode</td><td>'alert'</td><td>对话框模式</td><td>alert/right:有确定按钮&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />confirm:有确定和取消按钮&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />notice:有确定按钮&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />info:没有按钮&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td></tr><tr><td>t</td><td>'提示信息'</td><td>对话框标题</td><td><br /></td></tr><tr><td>func</td><td><br /></td><td>点&quot;确定&quot;执行的函数</td><td><br /></td></tr><tr><td>cover</td><td>1 (mode = 'info' 时为 0)</td><td>是否显示一个遮罩覆盖整个页面</td><td>1:是&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />0:否&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td></tr><tr><td>funccancel</td><td><br /></td><td>点&quot;取消&quot;执行的函数</td><td><br /></td></tr><tr><td>leftmsg</td><td><br /></td><td>底部左侧信息</td><td><br /></td></tr><tr><td>confirmtxt</td><td>'确定'</td><td>确定按钮的文字</td><td><br /></td></tr><tr><td>canceltxt</td><td>'取消'</td><td>取消按钮的文字</td><td><br /></td></tr><tr><td>closetime</td><td><br /></td><td>自动关闭的时间,单位&quot;秒&quot;leftmsg 强制更改为&quot;n 秒后窗口关闭&quot;</td><td><br /></td></tr><tr><td>locationtime</td><td><br /></td><td>自动跳转时间,单位&quot;秒&quot;leftmsg 强制更改为&quot;n 秒后页面跳转&quot;</td><td><br /><br /><br /><font size="4"><font color="DarkRed"><strong>showWindow() AJAX弹窗</strong><br /></font></font><font size="4"><font color="DarkRed"><strong>showWindow(k, url, mode, cache, v)</strong></font></font><br />参数如下:<br /><table cellspacing="0" class="t_table" ><tr><td width="110"><strong>key</strong></td><td width="190"><strong>默认值</strong></td><td width="230"><strong>含义</strong></td><td><strong>可选值及解释</strong></td></tr><tr><td>k</td><td>(必填)</td><td>浮窗的 key</td><td><br /></td></tr><tr><td>url</td><td>(必填)</td><td>get 方式 url 表示浮窗请求的地址post 方式 url 表示浮窗提交的表单 id</td><td><br /></td></tr><tr><td>mode</td><td>'get'</td><td>弹窗请求类型</td><td>get: ajaxget 方式请求 url&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />post: ajaxpost 方式请求 url&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td></tr><tr><td>cache</td><td>1</td><td>是否缓存弹窗内容</td><td>1:是&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />0:否&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td></tr><tr><td>v</td><td><br /></td><td>由于 showWindow() 是以 showMenu() 函数为内核,因此此处可微调 showMenu() 参数,如不指定则使用 showWindow() 的默认值</td><td><br />注意:同一页面同时可以弹出多个浮窗,但 k 及 url 相同的浮窗同时只能显示一个浮窗标题区域支持拖拽关闭浮窗请使用 hideWindow(k);<br /><br /><font size="4"><br /><font color="DarkRed"><strong>showPrompt() 弹出提示</strong><br /><strong>showPrompt(ctrlid, evt, msg, timeout, classname)</strong></font></font><br />参数如下:<br /><table cellspacing="0" class="t_table" ><tr><td width="110"><strong>key</strong></td><td width="190"><strong>默认值</strong></td><td width="230"><strong>含义</strong></td><td><strong>可选值及解释</strong></td></tr><tr><td>ctrlid</td><td>null</td><td>控制菜单的 id</td><td><br /></td></tr><tr><td>evt</td><td>null</td><td>响应函数的事件</td><td>click: ctrlObj 的 onclick 触发&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />mouseover: ctrlObj 的 onmouseover 触发&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; </td></tr><tr><td>msg</td><td>(必填)</td><td>提示信息内容</td><td><br /></td></tr><tr><td>timeout</td><td>1500</td><td>显示持续时间</td><td>单位:毫秒</td></tr><tr><td>classname</td><td>(选填)</td><td>控制对象在弹出后的 class 值</td><td><br />showPrompt(null, null, '操作成功', 1500, 'newbox');<br /><br /><br /><font size="4"><font color="DarkRed"><strong>ajaxget() AJAX/GET请求</strong><br /><strong>ajaxget(url, showid, waitid, loading, display, recall)</strong></font></font><br />参数如下:<br /><table cellspacing="0" class="t_table" ><tr><td width="110"><strong>key</strong></td><td width="190"><strong>默认值</strong></td><td><strong>含义</strong></td></tr><tr><td>url</td><td>(必填)</td><td>请求的 url</td></tr><tr><td>showid</td><td>(必填)</td><td>ajax 返回信息显示区域的 id</td></tr><tr><td>waitid</td><td>showid</td><td>ajax 请求过程中显示等待信息区域的 id</td></tr><tr><td>display</td><td><br /></td><td>信息返回后 showId 的 style.display 值</td></tr><tr><td>recall</td><td><br /></td><td>信息返回后执行的代码ajax返回内容中的标记可增加如下几个属性,可让链接自动实现ajaxget功能<br />ajaxtarget: 属性含义同 ajaxget() 的 showid<br />ajaxwaitid: 属性含义同 ajaxget() 的 waitid<br />ajaxloading: 属性含义同 ajaxget() 的 loading<br />ajaxdisplay: 属性含义同 ajaxget() 的 display<br />ajaxfunc:属性含义同 ajaxget() 的 recall<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<br /><font size="4"><font color="DarkRed"><strong>ajaxpost() AJAX/POST请求</strong><br /><strong>ajaxpost(formid, showid, waitid, showidclass, submitbtn, recall)</strong></font></font><br />参数如下:<br /><table cellspacing="0" class="t_table" ><tr><td width="110"><strong>key</strong></td><td width="190"><strong>默认值</strong></td><td><strong>含义</strong></td></tr><tr><td>formid</td><td>(必填)</td><td>ajax 提交的表单 id</td></tr><tr><td>showid</td><td>(必填)</td><td>ajax 返回信息显示区域的 id</td></tr><tr><td>waitid</td><td>showid</td><td>ajax 请求过程中显示等待信息区域的 id</td></tr><tr><td>showidclass</td><td><br /></td><td>表单提交后返回信息显示区域的样式</td></tr><tr><td>submitbtn</td><td><br /></td><td>表单提交按钮 ajax 请求发出后将会禁用这个按钮</td></tr><tr><td>recall</td><td><br /></td><td>信息返回后执行的代码菜单<em>, </em>显示<em>, </em>size
頁: [1]
查看完整版本: Discuz! 前端 JS 常用函数解释