javascript 链接

javascript 函数,可以放在一个外部的common.js文件中

引入:<script src="http://www.cnblogs.com/js/common.js" type="text/JavaScript"></script>

ContractedBlock.gif ExpandedBlockStart.gif Code
function openwindow(url,name,iWidth,iHeight)
 {
  
var iTop = (window.screen.availHeight-30-iHeight)/2;       //获得窗口的垂直位置;
  var iLeft = (window.screen.availWidth-10-iWidth)/2;           //获得窗口的水平位置;
 window.open(url,name,'height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no');
  
//window.open(url,name,'height='+iHeight+',width='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=yes,resizeable=yes,location=no,status=yes');
 }
 
function openwindowscroll(url,name,iWidth,iHeight)
 {
  
var iTop = (window.screen.availHeight-30-iHeight)/2;       //获得窗口的垂直位置;
  var iLeft = (window.screen.availWidth-10-iWidth)/2;           //获得窗口的水平位置;
 window.open(url,name,'height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,status=no,scrollbars=yes,resizable=yes');
  
//window.open(url,name,'height='+iHeight+',width='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=yes,resizeable=yes,location=no,status=yes');
 }
  
        
function ___doPostBack(eventTarget, eventArgument) 
        { 
        
var theform = document.forms['form1']; 
        
if (!theform) 
        { 
        theform 
= document.form1; 
        } 
        theform.__EVENTTARGET.value 
= eventTarget ;
        theform.__EVENTARGUMENT.value 
= eventArgument; 
        theform.submit();
        }
   
function openWindows(url, width, heigth)    
   {
        
var res=window.showModalDialog(url,window,"status:false;resizable:yes;dialogWidth:"+width+"px;dialogHeight:"+heigth+"px");
        
if(res=="pleasefresh")
        {
         refresh();
        }
   }
ContractedBlock.gif ExpandedBlockStart.gif Code
在前台调用该函数:  
   
   
function OpenWindow()
   {   
    
     
var xn=document .getElementById ("ddlstXn");
     
var xq=document .getElementById ("ddlstXq");
     
var bh=document .getElementById ("txtBh");
     
if(xn.selectedIndex==0||xq.selectedIndex==0||bh.value.length==0)
     {
        alert (
"请输入学年+学期+班号");
        
return false;
     }
     
else
     {
        openwindow(
"CourseGradeRPT.aspx?xn="+xn.value+"&xq="+xq.value+"&bh="+bh.value+""null ,900,600);
     }
    
   }

<asp:button  CssClass="bt_query"  text ="  综合查询" id="btnAllQueryGrade"  runat="server"  OnClientClick="OpenWindow();" />

--------------------------------------------------------------------------------------------------------------------------------------
在后台调用前台js函数:  

 
function OpenWindowPrint(url)
   {
       openwindow(url ,
null,800,600);
   }

1.string url = "GradeQueryClassRPT.aspx?xn=" + this.hidXn.Value + "&xq=" + this.hidXq.Value + "&bh=" + this.hidBh.Value+"&kc="+Server.UrlEncode(this.ddlstCourseCode.SelectedItem.Text);
Page.ClientScript.RegisterStartupScript(
this.GetType(), """ <script type='text/JavaScript'>OpenWindowPrint('" + url + "'); </script>");

2.Response.Write(" <script type='text/JavaScript'>window.open('" + url + "'); </script>");//按钮会变样    

3.Page.ClientScript.RegisterStartupScript(this.GetType(), """ <script type='text/JavaScript'>window.open('" + url + "'); </script>");

 

ContractedBlock.gif ExpandedBlockStart.gif Code
string urllink = "GradeQueryClassRPT.aspx?xn=" + this.hidXn.Value + "&xq=" + this.hidXq.Value + "&bh=" + this.hidBh.Value;
string url
=" <script type='text/JavaScript'>OpenWindowPrint('" + urllink + "'); </script> "  

this.btnOpen.Attributes.Add("onclick", OnAddClientClick);       //放在pageload里面    

弹出模式对话框 

/// <param name="page">要执行的页面对象</param> 
        /// <param name="URL">要打开的页面地址</param> 
        /// <param name="width">宽</param> 
        /// <param name="height">高</param> 
        public static string Fpage_f_win_opendialog_returnvalue(System.Web.UI.Page page, string URL, int width, int height)
        {
            string js2 
= "javascript:";
            js2 
+= string.Format("res=window.showModalDialog(\"{0}\",window,\"status:no;resizable:no;dialogWidth:{1}px;dialogHeight:{2}px\");", URL, width.ToString(), height.ToString());
            js2 
+= "if (res==\"pleasefresh\")" + " {" + " refresh();" + "}";
            
//js2 += string.Format("res=window.showModalDialog(\"{0}\",window,\"status:false;resizable:yes;dialogWidth:{1}px;dialogHeight:{2}px\");", URL, width.ToString(), height.ToString());
            return js2;
            
//page.RegisterClientScriptBlock("can", js2);
        }

Onclick事件字符串
 string OnAddClientClick 
= CommonPage.Fpage_f_win_opendialog_returnvalue(this.Page, "TeacherAdd.aspx"850600);
 
//绑定新增按钮Onclick
this.btnAdd.Attributes.Add("onclick", OnAddClientClick);

转载于:https://www.cnblogs.com/hubcarl/archive/2009/05/10/1453473.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值