放一个javascript右键菜单的代码
注册很长时间号了,刚开通博客,拿出一个自己写的javascript右键菜单,兼容IE,firefox浏览器
这是css代码
body{
font-size:12px;
}
.contextMenu{
filter:alpha(opacity=80);
opacity:0.8;
border:1px #0033FF solid;
background-color:#0099CC;
cursor:pointer;
width:120px;
position:absolute;
top:0;
left:0;
font-size:12px;
}
.cmddiv{
padding:2px;
border-bottom:1px #00FF99 dotted;
}
还有javascript代码
window.onload=function(){
var contextMenu;
var buttons=['菜单1','菜单2','菜单3','菜单4'];
window.document.body.oncontextmenu=function(e){
var xy=getXY(e);
if(typeof contextMenu!="object"){
contextMenu=document.createElement("div");
for(var i=0;i<buttons.length;i++){
var div=document.createElement("div");
var cmd=document.createTextNode(buttons[i]);
div.eventDiv=i;
div.className="cmddiv";
div.appendChild(cmd);
contextMenu.appendChild(div);
}
contextMenu.className="contextMenu";
window.document.body.appendChild(contextMenu);
contextMenu.onclick=function(e){
var e = e||window.event;
var target=e.target||e.srcElement;
alert(target.eventDiv);
}
}
contextMenu.style.display="";
contextMenu.style.top=xy.y+10+"px";
contextMenu.style.left=xy.x+10+"px";
return false;
}
window.document.body.onclick=function(){
if(typeof contextMenu=="object"){
contextMenu.style.display="none";
}
}
var getXY=function(e){
var x,y;
var e = e||window.event;
return {x:e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,y:e.clientY+document.body.scrollTop+document.documentElement.scrollTop};
}
}
代码只写到判断出点击的是那个命令,至于要实现的函数,还是要自己写的
相关文档:
JavaScript gives HTML designers a programming tool - HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages
JavaScript can put dynamic text into an HTML page - A Ja ......
在silverlight开发中,我们可以使用js来调用silverlight中的方法(当然方法上要捆绑相应属性),也可以将指定
的js方法绑定到silverlight应用中的事件上.本DEMO演示了通过js调用完成silverlight数据列表控件(DataGrid)的数
据绑定操作,并通过DataGrid的EmployeeList_BeginningCellEdit事件将当前选取的数据行信息返回到 ......
最近太忙,没有时间总结工作内容了,忙里偷闲吧,共享下我的JavaScript MD5 脚本
var hex_chr = "0123456789abcdef";
function rhex(num)
{
str = "";
for(j = 0; j <= 3; j++)
str += hex_chr.charAt((num >> (j * 8 + 4)) & 0x0F) +
hex_chr.charAt((num >> (j * 8)) & 0x0F);
re ......
//1.类
function Test(id)
{
this.id=id;
this.method=function()
{
//代码
};
}
......
在javascript代码中用encodeURIComponent()函数处理中文字符串,
JS代码:
<mce:script type=”text/javascript”><!--
string = encodeURIComponent(string);
location.href = index.php?keyword=’+string;
// --></mce:script>
PHP代码:
<?php
$keyword = (isset($_GET ......