1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

谁可以编写一段 JavaScript 呢?

本帖由 Ulysses2008-07-01 发布。版面名称:前端开发

  1. Ulysses

    Ulysses New Member

    注册:
    2006-02-05
    帖子:
    10,018
    赞:
    16
    实现目标:点击链接,显示下拉菜单效果。

    如同点击论坛上面的“搜索”和“快速链接”,以求尽可能通用。
     
  2. A君

    A君 Well-Known Member

    注册:
    2005-08-31
    帖子:
    19,987
    赞:
    98
    我看蓝色理想有个的
     
  3. A君

    A君 Well-Known Member

    注册:
    2005-08-31
    帖子:
    19,987
    赞:
    98
    那人是要QQ中转站那个点击下载,弹出一个小页面。
     
  4. Ulysses

    Ulysses New Member

    注册:
    2006-02-05
    帖子:
    10,018
    赞:
    16
    有地址?
     
  5. A君

    A君 Well-Known Member

    注册:
    2005-08-31
    帖子:
    19,987
    赞:
    98
    不记得了
     
  6. A君

    A君 Well-Known Member

    注册:
    2005-08-31
    帖子:
    19,987
    赞:
    98
    我看看我有没有保存
     
  7. A君

    A君 Well-Known Member

    注册:
    2005-08-31
    帖子:
    19,987
    赞:
    98
    看看这个行么?

    代码:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    		<title>Untitled Document</title>
    		<style type="text/css">
    			#keleSelect{
    				TEXT-DECORATION: none;
    			}
    			body {
    				margin:0;
    				padding:0;
    			}
    		</style>
    		<script type="text/javascript" >
    			var ary = new Array;
    			var tableAlign = "left" // left|right
    			ary.push( {
    				img:"",
    				url:"http://www.kele-cn.cn",
    				title:"回复所有人"
    			}) ;
    			ary.push( {
    				img:"",
    				url:"http://www.kele-cn.cn",
    				title:"转发"
    			});
    			ary.push( {
    				img:"",
    				url:"http://www.kele-cn.cn",
    				title:"打印"
    			});
    			ary.push( {
    				img:"",
    				url:"http://www.kele-cn.cn",
    				title:"将 rubyonrails-spinoffs 添加到通讯录"
    			});
    			ary.push( {
    				img:"",
    				url:"http://www.kele-cn.cn",
    				title:"删除此邮件"
    			});
    			ary.push( {
    				img:"",
    				url:"http://www.kele-cn.cn",
    				title:"这是网络欺诈"
    			});
    			ary.push( {
    				img:"",
    				url:"http://www.kele-cn.cn",
    				title:"显示原始邮件"
    			});
    			ary.push( {
    				img:"",
    				url:"http://www.kele-cn.cn",
    				title:"邮件内容出现乱码?"
    			});
    			function addOnLoad(newFunction) {
    				var oldFun = window.onload;
    				if(typeof window.onload != "function") {
    					window.onload = newFunction;
    				}else {
    					window.onload = function() {
    						oldFun();
    						newFunction();
    					}
    				}
    			}
    			function trOnclick(obj) {
    				var keleKey = document.getElementById("keleKey");
    				var url = ary[obj.i].url + "?key=" + keleKey.value;
    				location.href = url;
    			}
    			function prepareKeleTable() {
    				var keleTr = document.getElementById("keleTable").getElementsByTagName("tr");
    				var trCount = keleTr.length
    				for(var i=0;i<trCount;++i) {
    				keleTr.onmouseout = function() {this.style.backgroundColor = "#EEEEEE";};
    				keleTr.onmouseover = function() {this.style.backgroundColor = "#CCCCCC";};
    				keleTr.onclick = function(){ trOnclick(this); }
    				}
    			}
    			/**
    			 * 
    			 * @param {Object} table
    			 * @info 设置table样式
    			 */
    			function keleSelectStyle(obj,table) {
    				table.style.border = "#CCCCCC solid 1px";
    				table.style.backgroundColor = "#EEEEEE";
    				table.style.color="#496397";
    				table.style.borderCollapse="collapse";
    				table.style.fontFamily = "arial,sans-serif";
    				table.style.fontSize = "14px";
    				table.style.lineHeight="20px";
    				table.style.position = "absolute";
    				table.style.top = obj["offsetHeight"]+ calculateOffsetTop(obj) + "px";
    				if (tableAlign == "left") {
    					table.style.left = calculateOffsetLeft(obj) + "px";
    				} else {
    					table.style.right = document.body.offsetWidth - calculateOffsetLeft(obj) -obj.offsetWidth  + "px";
    				}
    			}
     			function keleSelectOnclick(obj){
                                         clearTable();
    				var table = document.createElement("table");
    				table.setAttribute("id","keleTable");
    				keleSelectStyle(obj,table);
    				var tbody = document.createElement("tbody");
    				for(var i=0;i<ary.length;++i) {
    					var tr = document.createElement("tr");
    					tr.i = i;
    					var td1 = document.createElement("td");
    					var td2 = createTd(ary.title);
    					var img = createImg(ary.img);
    					td1.style.padding = "1px";
    					td1.width = "18px";
    					td1.appendChild(img);
    					td2.style.padding = "1px";
    					tr.appendChild(td1);
    					tr.appendChild(td2);
    					tr.style.cursor = "pointer";
    					tbody.appendChild(tr);
    				}
    				table.appendChild(tbody);
    				document.body.appendChild(table);
    				prepareKeleTable();
    				
    				/*
    				if(document.getElementById("keleTable")) {
    					alert("yes");
    					alert(document.getElementById("keleTable").innerHTML);
    				} else {
    					alert("no");
    				}
    				*/
    			}
    			function prepareKeleSelect() {
    			 var keleSelect = document.getElementById("keleSelect");
    			 keleSelect.onblur = function() { setTimeout("clearTable()",100);}
    			 keleSelect.onclick = function() { keleSelectOnclick(this); return false;};
    			 
    			}
    			function calculateOffsetLeft(field) {
    				return calculateOffset(field,"offsetLeft");
    			}
    			function calculateOffsetTop(field) {
    				return calculateOffset(field,"offsetTop");
    			}
    			function calculateOffset(field,attr) {
    				if(field) {
    					return field[attr] + calculateOffset(field.offsetParent, attr);
    				} else {
    					return 0;
    				}
    			}
    			function clearTable() {
    				if(!document.getElementById("keleTable")) return false;
    				var keleTable = document.getElementById("keleTable");
    				document.body.removeChild(keleTable);
    			}
    			function createTd(text){
    				var td = document.createElement("td");
    				var textNode = document.createTextNode(text);
    				td.appendChild(textNode);
    				
    				return  td;
    			}
    			function createImg(url) {
    				if (url != "") {
    					var img = document.createElement("img");
    					img.setAttribute("src", url);
    					return img;
    				} else {
    					var text = document.createTextNode(" ");
    					return text;
    				}
    			}
    			addOnLoad(prepareKeleSelect);
    		</script>
    	</head>
    	<body>
    	<div style="margin:0 auto;text-align:center;">
    		<h1><a id="keleSelect" href="#"></>OnClick</a></h1>
    		<input type="hidden" id="keleKey" name="keleKey" value="KeleKeyyyyyyyy">
    	</div>
    	</body>
    </html>
     
  8. A君

    A君 Well-Known Member

    注册:
    2005-08-31
    帖子:
    19,987
    赞:
    98
    那个QQ,我没保存
     
  9. Kevin

    Kevin New Member

    注册:
    2005-10-23
    帖子:
    12,728
    赞:
    55
    js我只会乱改!!看都不一定能看懂~
     
  10. Ulysses

    Ulysses New Member

    注册:
    2006-02-05
    帖子:
    10,018
    赞:
    16
  11. A君

    A君 Well-Known Member

    注册:
    2005-08-31
    帖子:
    19,987
    赞:
    98
    不懂这些东西
     
  12. junp

    junp New Member

    注册:
    2005-11-06
    帖子:
    1,259
    赞:
    4
    就用论坛上面那个
     
  13. recycle

    recycle New Member

    注册:
    2005-09-25
    帖子:
    2,342
    赞:
    11
    自己多看几个页面,喜欢的就拷下来。