protected void LinkButton2_Click(object sender, EventArgs e)
{
RegisterStartupScript("script", "<script>myfunNews('短发','我已剪短我的髮','0','','600','200');</script>");
}<script type="text/javascript">
function myfunNews(title, content,num, path, w, h) //新闻显示
{
function HTMLDeCode(str)
{
var s = "";
if (str.length == 0) return "";
s = str.replace(/&/g, "&");
s = s.replace(/</g, "<");
s = s.replace(/>/g, ">");
s = s.replace(/ /g, " ");
s = s.replace(/'/g, "\'");
s = s.replace(/"/g, "\"");
s = s.replace(/<br>/g, "\n");
s = s.replace(/'/g, "\'");
return s;
}
var titleheight = "22px"; // 提示窗口标题高度
var bordercolor = "#8888ff"; //提示窗口的边框颜色
var titlecolor = "#FFFFFF"; //提示窗口的标题颜色
var titlebgcolor = "#8888ff"; // 提示窗口的标题背景色
var bgcolor = "rgb(239,239,239)"; // 提示内容的背景色
var iWidth =window.screen.width-20 ;
var iHeight = window.screen.height;
iHeight=iHeight>768?(iHeight-155):(iHeight-80);
var dWidth=(iWidth-w)/2; //弹出窗口距离left的宽度
var dHeight=(iHeight-h)/2;//弹出窗口距离top的高度 114
var msgObj=document.createElement("div");
msgObj.id="msgObj";
msgObj.style.cssText = "position:absolute;left:0px;top:0px;font:11px '宋体';width:"+w+"px;height:"+h+"px;text-align:center;border:1px solid "+bordercolor+";background-color:"+bgcolor+";padding:1px;line-height:22px;z-index:105;";
document.body.appendChild(msgObj); //以上是弹出消息的div层
var divs = document.getElementById("msgObj");
var table = document.createElement("table");
msgObj.appendChild(table); //消息框中添加table
table.style.cssText = "margin:0px;border:0px;padding:0px;";
table.cellSpacing = 0;
var tr = table.insertRow(-1);
var titleBar = tr.insertCell(-1); //标题
titleBar.style.cssText = "width:100%;height:"+titleheight+"px;text-align:left;padding:3px;margin:0px;font:bold 12px '宋体';color:"+titlecolor+";border:1px solid " + bordercolor + ";background-color:" + titlebgcolor;
titleBar.style.paddingLeft = "10px";
titleBar.innerHTML = title;
var adjunct=tr.insertCell(-1);//附件
adjunct.style.cssText = "left:520px;position:absolute;top:3px;cursor:pointer;width:50%;height:"+titleheight+"px;text-align:right;padding:3px;margin:0px;font:bold 12px '宋体';color:"+titlecolor+";text-decoration: underline;border:1px solid " + bordercolor + ";background-color:" + titlebgcolor;
adjunct.style.paddingLeft = "10px";
if(num==0)
{
adjunct.style.cssText = "left:280px;position:absolute;top:2px;cursor:auto;width:50%;height:"+titleheight+"px;text-align:right;padding:3px;margin:0px;font:bold 12px '宋体';color:red;text-decoration: underline;border:1px solid " + bordercolor + ";background-color:" + titlebgcolor;
adjunct.style.paddingLeft = "10px";
adjunct.innerHTML="";
}
else
{
adjunct.innerHTML="附件";
adjunct.onclick=function() //点击附件的事件
{
document.getElementById("btn_path").click();
}
}
var closeBtn = tr.insertCell(-1); //关闭按钮
closeBtn.style.cssText = "cursor:pointer; padding:2px;background-color:" + titlebgcolor;
closeBtn.innerHTML = "<span style='font-size:12pt; color:"+titlecolor+";'>×</span>"; // 关闭div按钮
closeBtn.onclick = function()//触发的事件
{
document.body.removeChild(bgObj);
document.body.removeChild(msgObj);
}
var msgBox = table.insertRow(-1).insertCell(-1);
msgBox.style.cssText = "font:10pt '宋体';text-align:left;";
msgBox.colSpan = 2;
msgBox.innerHTML = "<html>"+ content +"</html>"; // 获得事件Event对象,用于兼容IE和FireFox
var hh=divs.scrollHeight;
var ww=divs.scrollWidth;
iWidth=iWidth>ww?iWidth:ww; //计算宽度
iHeight=iHeight>hh?iHeight:(dHeight+hh);//计算高度
hh=hh<h?h:hh;
msgObj.style.left=(iWidth-ww)/2;
msgObj.style.top=(iHeight-hh)/2;
var bgObj = document.createElement("div");
bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+iHeight+"px;filter:Alpha(Opacity=50);opacity:0.3;background-color:#000000;z-index:101;";
document.body.appendChild(bgObj); //以上div是背景
function getEvent()
{
return window.event || arguments.callee.caller.arguments[0];
}
}
</script>注意:
点击gridview中的linkbutton,调用myfunNews,显示新闻的标题以及内容,同样的方法,有的LinkButton调用就正常显示,有一些LinkButton调用myfunNews方法,就出现上面图片中的错误,为什么,怎么解决?
同样的方法,调用的方式一样,同样的gridview或LinkButton会出现不同的效果。
有些电脑可以正常显示,有些人的电脑就出现图片中的问题。求高手解决,谢谢。
在哪里添加?linkbutton中不允许,你说添加到哪里啊。
都没有onclink事件,换控件有什么用啊。能解释下吗?
为什么要用linkbutton
版主很給力,解决。
ClientScript.RegisterStartupScript(GetType(), "show", "<script defer>show();</script>"); 另求版主的QQ群。