老板的奇思妙想:下拉菜单中嵌套二级菜单

shzrxml 2003-12-08 08:37:24
下拉菜单中嵌套二级菜单
意思是在下拉菜单中实现二级菜单的功能,就像普通的下拉菜单一样.
...全文
109 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhlym 2004-01-10
  • 打赏
  • 举报
回复
TO inelm(Archimond 【阿克蒙德】)

看了源码,有两个CSS和一个VBS下载之后就是没效果,不知怎回事!
nchen123 2004-01-10
  • 打赏
  • 举报
回复
这是孟子老大的网站,代码我也没有, 你有兴趣的话自己看源代码慢慢扒下来好了。
zhlym 2004-01-10
  • 打赏
  • 举报
回复
TO inelm(Archimond 【阿克蒙德】)

这个网址http://xml.sz.luohuedu.net/xml/CoolMenu/main.htm
打开窗口很特别,我想要代码,能给一份吗?
邮箱: email-lym@163.com
minghui000 2004-01-10
  • 打赏
  • 举报
回复
晕!
dgseamaple 2003-12-11
  • 打赏
  • 举报
回复
关注ing......
actor2222 2003-12-11
  • 打赏
  • 举报
回复
mark
awaysrain 2003-12-09
  • 打赏
  • 举报
回复
function toggleDropDown(el) {
if (el.size == 1) {
dropDown = el.children[1];
if (dropDown.style.visibility == "")
dropDown.style.visibility = "hidden";
if (dropDown.style.visibility == "hidden")
showDropDown(dropDown);
else
hideDropDown(dropDown);
}
}
function optionClick() {
el = getReal(window.event.srcElement, "className", "option");
if (el.className == "option") {
dropdown = el.parentElement;
selectBox = dropdown.parentElement;
oldSelected = dropdown.children[findSelected(selectBox)]
if(oldSelected != el) {
oldSelected.removeAttribute("selected");
el.setAttribute("selected", 1);
selectBox.selectedIndex = findSelected(selectBox);
}
if (selectBox.onchange != null) { // This executes the onchange when you chnage the option
if (selectBox.id != "") { // For this to work you need to replace this with an ID or name
eval(selectBox.onchange.replace(/this/g, selectBox.id));
}
else {
globalSelect = selectBox;
eval(selectBox.onchange.replace(/this/g, "globalSelect"));
}
}
if (el.backupCss != null)
el.style.cssText = el.backupCss;
copySelected(selectBox);
toggleDropDown(selectBox);
highlightSelected(selectBox, true);
}
}
function optionOver() {
var toEl = getReal(window.event.toElement, "className", "option");
var fromEl = getReal(window.event.fromElement, "className", "option");
if (toEl == fromEl) return;
var el = toEl;
if (el.className == "option") {
if (el.backupCss == null)
el.backupCss = el.style.cssText;
highlightSelected(el.parentElement.parentElement, false);
el.style.cssText = el.backupCss + "; " + overOptionCss;
this.highlighted = true;
}
}
function optionOut() {
var toEl = getReal(window.event.toElement, "className", "option");
var fromEl = getReal(window.event.fromElement, "className", "option");
if (fromEl == fromEl.parentElement.children[findSelected(fromEl.parentElement.parentElement)]) {
if (toEl == null)
return;
if (toEl.className != "option")
return;
}
if (toEl != null) {
if (toEl.className != "option") {
if (fromEl.className == "option")
highlightSelected(fromEl.parentElement.parentElement, true);
}
}
if (toEl == fromEl) return;
var el = fromEl;
if (el.className == "option") {
if (el.backupCss != null)
el.style.cssText = el.backupCss;
}
}
function highlightSelected(el,add) {
var selectedIndex = findSelected(el);
selected = el.children[1].children[selectedIndex];
if (add) {
if (selected.backupCss == null)
selected.backupCss = selected.style.cssText;
selected.style.cssText = selected.backupCss + "; " + overOptionCss;
}
else if (!add) {
if (selected.backupCss != null)
selected.style.cssText = selected.backupCss;
}
}
function hideShownDropDowns() {
var el = getReal(window.event.srcElement, "className", "select");
var spans = document.all.tags("SPAN");
var selects = new Array();
var index = 0;
for (var i=0; i<spans.length; i++) {
if ((spans[i].className == "select") && (spans[i] != el)) {
dropdown = spans[i].children[1];
if ((spans[i].size == 1) && (dropdown.style.visibility == "visible"))
selects[index++] = dropdown;
}
}
for (var j=0; j<selects.length; j++) {
hideDropDown(selects[j]);
}
}
function hideDropDown(el) {
if (typeof(fade) == "function")
fade(el, false);
else
el.style.visibility = "hidden";
}
function showDropDown(el) {
if (typeof(fade) == "function")
fade(el, true);
else if (typeof(swipe) == "function")
swipe(el, 2);
else
el.style.visibility = "visible";
}
function initSelectBoxes() {
var spans = document.all.tags("SPAN");
var selects = new Array();
var index = 0;
for (var i=0; i<spans.length; i++) {
if (spans[i].className == "select")
selects[index++] = spans[i];
}
for (var j=0; j<selects.length; j++) {
initSelectBox(selects[j]);
}
}
function getReal(el, type, value) {
temp = el;
while ((temp != null) && (temp.tagName != "BODY")) {
if (eval("temp." + type) == value) {
el = temp;
return el;
}
temp = temp.parentElement;
}
return el;
}
if (ie4) {
window.onload = initSelectBoxes;
document.onclick = hideShownDropDowns;
}
</SCRIPT>
<SCRIPT type=text/javascript>
function writeSelectBox(matrix, id, size, onchange, css) {
var d = window.document;
var ie4 = (document.all != null);
if (ie4) {
// alert("Before!");
var s = createIEString(matrix, id, size, onchange, css);
document.write(s);
// alert("After!");
// alert(s);
}
else {
document.write(createXString(matrix, id, size, onchange, css));
}
}
function createIEString(matrix, id, size, onchange, css) {
var str = "";
// Span startTag
str += '<span class="select"';
if (size == null)
size = 1;
str += ' size="' + size + '"';
if (id != null)
str += ' id="' + id + '"';
if (onchange != null)
str += ' onchange="' + onchange + '"';
if (css != null)
str += ' style="' + css + '"';
str += '>\n';
// Table Tag
str += '<table class="selectTable" cellspacing="0" cellpadding="0"\n';
str += ' onclick="toggleDropDown(this.parentElement)">\n';
str += '<tr>\n';
str += '<td class="selected"> </td>\n';
str += '<td align="CENTER" valign="MIDDLE" class="Button"\n';
str += ' onmousedown="this.style.border=\'2 inset buttonhighlight\'"\n';
str += ' onmouseup="this.style.border=\'2 outset buttonhighlight\'">\n';
str += '<span style="position: relative; left: 0; top: -2; width: 100%;">6</span></td>\n';
str += '</tr>\n';
str += '</table>\n';
// DropDown startTag
str += '<div class="dropDown" onclick="optionClick()" onmouseover="optionOver()" onmouseout="optionOut()">\n';
for (var i=0; i<matrix.length; i++) {
html = matrix[i].html;
value = matrix[i].value;
css = matrix[i].css;
selected = matrix[i].selected;
// Write option starttag
str += '<div class="option"';
if (value != null)
str += ' value="' + value + '"';
if (css != null)
str += ' style="' + css + '"';
if (selected != null)
str += ' selected';
str += '>\n';
// Write HTML contents
str += html;
// Write end tag
str += '</div>\n';
}
//DropDown endtag
str += '</div>\n';
// Span endTag
str += '</span>\n';
return str;
}
function createXString(matrix, id, size, onchange, css) {
// var str = "\n";
// form startTag
var str = '<form>\n';
// Select startTag
str += '<select';
if (size == null)
size = 1;
str += ' size="' + size + '"';
if (id != null)
str += ' id="' + id + '"';
if (onchange != null)
str += ' onchange="' + onchange + '"';
// if (css != null)
// str += ' style="' + css + '"';
str += '>\n';
// write options
for (var i=0; i<matrix.length; i++) {
html = matrix[i].html;
value = matrix[i].value;
css = matrix[i].css;
selected = matrix[i].selected;
// Write option starttag
str += '\n<option';
if (value != null)
str += ' value="' + value + '"';
// if (css != null)
// str += ' style="' + css + '"';
if (selected != null)
str += ' selected';
str += '>';
// Write HTML contents
str += stripTags(html);
// Write end tag
str += '</option>\n';
}
str += '\n</select>\n';
str += '</form>\n';
return str;
}
function stripTags(str) {
var s = 0;
var e = -1;
var r = "";
s = str.indexOf("<",e);
do {
r += str.substring(e + 1,s);
e = str.indexOf(">",s);
s = str.indexOf("<",e);
}
while ((s != -1) && (e != -1))
r += str.substring(e + 1,str.length);
return r;
}
function Option(html, value, css, selected) {
this.html = html;
this.value = value;
this.css = css;
this.selected = selected;
}
</SCRIPT>
<SCRIPT>
topArray = new Array();
topArray[0] = new Option('awaysrain', 'awaysrain');
topArray[1] = new Option('<select name="D1"><option>1</option><option>2</option></select>', 'select1');
topArray[2] = new Option('<nobr>test</nobr>', "test");
writeSelectBox(topArray, "select2", 1, "", "margin-left: 10; width: 140;");
</SCRIPT>
awaysrain 2003-12-09
  • 打赏
  • 举报
回复
还有问题,自己修改吧
===========================================================
<style type=text/css>
.select {
BORDER-BOTTOM: buttonface 0px inset; BORDER-LEFT: buttonface 0px inset; BORDER-RIGHT: buttonface 0px inset; BORDER-TOP: buttonface 0px inset; CURSOR: default; FONT: icon; WIDTH: 100px
}
.selected {
BACKGROUND: window; BORDER-BOTTOM: buttonface 0px inset; BORDER-LEFT: buttonface 0px inset; BORDER-RIGHT: buttonface 0px inset; BORDER-TOP: buttonface 0px inset; FONT: icon; PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px
}
.selectTable {
BACKGROUND: buttonface; BORDER-BOTTOM: buttonhighlight 2px inset; BORDER-LEFT: buttonhighlight 2px inset; BORDER-RIGHT: buttonhighlight 2px inset; BORDER-TOP: buttonhighlight 2px inset; HEIGHT: 100%; WIDTH: 100%
}
.option {
FONT: icon; PADDING-BOTTOM: 1px; PADDING-LEFT: 3px; PADDING-RIGHT: 3px; PADDING-TOP: 1px; WIDTH: 100%
}
.dropDown {
BACKGROUND: window; BORDER-BOTTOM: windowtext 1px solid; BORDER-LEFT: windowtext 1px solid; BORDER-RIGHT: windowtext 1px solid; BORDER-TOP: windowtext 1px solid; PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px; POSITION: absolute; VISIBILITY: hidden; WIDTH: 100%
}
.select .button {
BORDER-BOTTOM: buttonhighlight 2px outset; BORDER-LEFT: buttonhighlight 2px outset; BORDER-RIGHT: buttonhighlight 2px outset; BORDER-TOP: buttonhighlight 2px outset; FONT-FAMILY: webdings; FONT-SIZE: 11px; HEIGHT: 5px; PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px; WIDTH: 16px
}
</style>
<SCRIPT type=text/javascript>
var overOptionCss = "background: highlight; color: highlighttext";
var sizedBorderCss = "2 inset buttonhighlight";
var globalSelect; //This is used when calling an unnamed selectbox with onclick="this.PROPERTY"
var ie4 = (document.all != null);
var q = 0;
function initSelectBox(el) {
copySelected(el);
var size = el.getAttribute("size");
// These two lines combined with execution in optionClick() allow you to write:
// onchange="alert(this.options[this.selectedIndex].value)"
el.options = el.children[1].children;
el.selectedIndex = findSelected(el); //Set the index now!
// Some methods that are supported on the real SELECT box
el.remove = new Function("i", "int_remove(this,i)");
el.item = new Function("i", "return this.options[i]");
el.add = new Function("e", "i", "int_add(this, e, i)");
// The real select box let you have lot of options with the same NAME. In that case the item
// needs two arguments. When using DIVs you can't have two with the same NAME (or ID) and
// then there is no need for the second argument
el.options[el.selectedIndex].selected = true;
dropdown = el.children[1];
if (size != null) {
if (size > 1) {
el.size = size;
dropdown.style.zIndex = 0;
initSized(el);
}
else {
el.size = 1;
dropdown.style.zIndex = 99;
if (dropdown.offsetHeight > 200) {
dropdown.style.height = "200";
dropdown.style.overflow = "auto";
}
}
}
highlightSelected(el,true);
}
function int_remove(el,i) {
if (el.options[i] != null)
el.options[i].outerHTML = "";
}
function int_add(el, e, i) {
var html = "<div class='option' noWrap";
if (e.value != null)
html += " value='" + e.value + "'";
if (e.style.cssText != null)
html += " style='" + e.style.cssText + "'";
html += ">";
if (e.text != null)
html += e.text;
html += "</div>"
if ((i == null) || (i >= el.options.length))
i = el.options.length-1;
el.options[i].insertAdjacentHTML("AfterEnd", html);
}
function initSized(el) {
//alert("initSized -------->");
var h = 0;
el.children[0].style.display = "none";
dropdown = el.children[1];
dropdown.style.visibility = "visible";
if (dropdown.children.length > el.size) {
dropdown.style.overflow = "auto";
for (var i=0; i<el.size; i++) {
h += dropdown.children[i].offsetHeight;
}
if (dropdown.style.borderWidth != null) {
dropdown.style.pixelHeight = h + 4; //2 * parseInt(dropdown.style.borderWidth);
}
else
dropdown.style.height = h;
}
dropdown.style.border = sizedBorderCss;
el.style.height = dropdown.style.pixelHeight;
}
function copySelected(el) {
var selectedIndex = findSelected(el);
selectedCell = el.children[0].rows[0].cells[0];
selectedDiv = el.children[1].children[selectedIndex];
selectedCell.innerHTML = selectedDiv.outerHTML;
}
// This function returns the first selected option and resets the rest
// in case some idiot has set more than one to selcted :-)
function findSelected(el) {
var selected = null;
ec = el.children[1].children; //the table is the first child
var ecl = ec.length;
for (var i=0; i<ecl; i++) {
if (ec[i].getAttribute("selected") != null) {
if (selected == null) { // Found first selected
selected = i;
}
else
ec[i].removeAttribute("selected"); //Like I said. Only one selected!
}
}
if (selected == null)
selected = 0; //When starting this is the most logic start value if none is present
return selected;
}
  • 打赏
  • 举报
回复
我们都没看过select里面镶嵌select的。
不过我想你老板可能只是想实现某个功能,是不是你下拉菜单项目太多,而且是项目下有子项目的,你可以考虑用树状结构实现。
甘泉123 2003-12-09
  • 打赏
  • 举报
回复
老板有前途~~
angeldjd 2003-12-09
  • 打赏
  • 举报
回复
DW有插件做下拉菜单用的,特简单。。找不到的话管我要。zs365@msn.com
cdsun 2003-12-09
  • 打赏
  • 举报
回复
select不行


bananasmiling(hello找我)
这个兄弟啊,我为搂主说句话啊,你也别生气

别人有问题来这里问你为什么不让别人问呢?我觉得你说得很奇怪啊。别人都不问你的三角从哪里来?
awaysrain 2003-12-09
  • 打赏
  • 举报
回复
模拟吧,用select不行
shzrxml 2003-12-09
  • 打赏
  • 举报
回复
hehe, 没说清楚
我所指的下拉菜单是

<select name="D1" onChange="submit()">
<option>1</option>
<option>2</option>
</select>

这样的菜单可否实现!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
nchen123 2003-12-09
  • 打赏
  • 举报
回复
你想要的是这样的吧?
http://xml.sz.luohuedu.net/xml/CoolMenu/main.htm
qxs 2003-12-09
  • 打赏
  • 举报
回复
很麻烦的,用FLASH做
  • 打赏
  • 举报
回复
可以肯定用select实现不了那样的样式。
swich 2003-12-09
  • 打赏
  • 举报
回复
那得用div模拟了

select实现不了
shzrxml 2003-12-09
  • 打赏
  • 举报
回复
感谢大家的关心!!!

刚才看了awaysrain(绝对零度)(明天会更好)前辈的代码,十分佩服.

但小弟的意思与前辈依然不同

大家一定听说过"微软式下拉菜单",我想做的是实现类似的样式(包含二级菜单),但同时又是select的功能.例如点击IE上的"文件",然后跳出"新建"等,鼠标移到新建上,又有二级菜单弹出,现在要做的是把一级菜单(文件)变成SELECT.

密切关注哦!!!
bananasmiling 2003-12-08
  • 打赏
  • 举报
回复
你这个在网上找一下多的是..
不要到这里面来问的.

28,407

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧