November 2006 Entries

用JavaScript执行PostBack

早上实现了在子页面更新数据以后,父页面刷新树的功能 思路: 父页面有个隐藏的html button作为proxy,子页面保存完数据以后,用js调用父页面的html button的触发函数click(); 父页面有个asp.net的link button控件,text="",等于也是隐藏的,它负责调用后台cs代码里的负责刷新树的方法; 父页面的html button onclick的时候,__doPostBack('DoRefresh',''); 代码: 父页面apsx:  <input type="button" id="DoRefreshProxy" value="DO" onclick="__doPostBack('DoRefresh','');" style="display:none;" />  <asp:linkbutton id="DoRefresh" runat="server" onclick="DoRefresh_Click"  CausesValidation=False/>  <input type="button" id="DoRefreshProxy" value="DO" onclick="__doPostBack('DoRefresh','');" style="display:none;" /> 父页面cs:  protected void DoRefresh_Click(object sender, EventArgs e)  {       this.BindTree(this.tvBuilding.SelectedNodeIndex,1);  }  protected void DoRefresh_Click(object sender, EventArgs e) { this.BindTree(this.tvBuilding.SelectedNodeIndex,1); } 子页面cs:  Page.RegisterStartupScript("pb","<script>window.opener.document.getElementById('DoRefreshProxy').click();</script>");  Page.RegisterStartupScript("pb","<script>window.opener.document.getElementById('DoRefreshProxy').click();");

ASP.net按钮提交前执行javascript

here is the code... 在提交前执行一段js  <script language=“javascript“>  function doSomething()  {   // 执行自己的javascript   // 继续提交   this.click();}  </script>  <asp:button onmousedown=“doSomething()“ id=“someButton” Text="提交" runat="server">  </asp:button>  <script language=“javascript“> function doSomething() { // 执行自己的javascript // 继续提交 this.click();}

The "with" keyword in Javascript

from: http://javascript.about.com/library/blwith.htm The "with" keyword is used to specify an object to which all of the unreferenced properties and methods in a following block of code are to be applied. for example: Instead of coding   var x = document.body.scrollLeft;   document.write('text1');   document.write('text2');   document.write('text3');    var x = document.body.scrollLeft; document.write('text1'); document.write('text2'); document.write('text3'); you could use   with document {       var x = body.scrollLeft;       write('text1');       write('text2');       write('text3');   }    with document { ...

href="\#" vs. href="javascript:void(0)"

开发的时候有时需要用link(<a>)来触发一些javascript事件,所以常常可以看到如下的代码:  <a href="javascript:void(0)" xxxxx="doSomething();return false;">Link</a>  <a href="javascript:void(0)" xxxxx="doSomething();return false;">Link这是一个曾经被多次讨论过的问题,长期以来,我也一直是这样写的。读了 a href=”javascript:void(0);” _fcksavedurl="”javascript:void(0);”" _fcksavedurl="”javascript:void(0);”" — avoid the void 之后,我认同了作者的意见。下面的写法确实更合理:  <a href="#" xxxxx="doSomething();return false;">Link</a>  <a href="#" xxxxx="doSomething();return false;">Link 或者  <script type="javascript">  function doSomething() {    //doSomething    return false;  }  </script>  <a href="#" xxxxx="return doSomething();">Link</a>  <script type="javascript"> function doSomething() { //doSomething return false; } Link以往大家不使用"#"的问题是,这将导致点击链接时页面跳回页面顶部,但通过 return false 语句将使得浏览器忽略链接的默认动作,从而避免了此问题。 youngpup 更有意思,他在How to Create Pop-Up Windows 中言辞激烈的倡导大家永远永远永远不要使用 javascript: 伪协议: Never, ever, ever use the javascript: pseudo-protocol for anything, ever ever ever ever again. Please. Pretty please. 他的解决方案是:  <a     href="http://google.com/"    xxxxx="window.open(this.href, 'popupwindow',     'width=400,height=300,scrollbars,resizable');     return false;">  <a href="http://google.com/" xxxxx="window.open(this.href, 'popupwindow', 'width=400,height=300,scrollbars,resizable'); return false;">这样的好处就是可以保存到书签或者收藏夹,可以左键单击,也可以右键使用!form Ajax中国

View posts by date
«November»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789