【asp.net 小札記】小知識點

1、jquery操作frame元素
    1.1在父窗口中操作 選中IFRAME中的所有單選鈕
    $(window.frames["iframe1"].document).find("input[@type='radio']").attr("checked","true");
    1.2 在IFRAME中操作 選中父窗口中的所有單選鈕
     $(window.parent.document).find("input[@type='radio']").attr("checked","true");

    1.3 $(document.getElementById('iframeId').contentWindow.document.body).htm() 
    1.4 顯示frame中元素:$("#testId", document.frames["iframename"].document).html();
2、http://www.jb51.net/article/24101.htm 閉包可以用在許多地方。它的最大用處有兩個,一個是前面提到的可以讀取函數內部的變量,另一個就是讓這些變量的值始終保持在內存中。
3、後臺執行js代碼:
   當使用了ScriptManager後:System.Web.UI.ScriptManager.RegisterStartupScript(control, type, "NULL", script, addScriptTags)
   沒有使用ScriptManager:Page.ClientScript.RegisterStartupScript(ClientScript.GetType(), "key", script);

4、將普通頁面的方法公佈爲WebMethod,以Javascript形式訪問。
5、webMethod的命名空間爲System.Web.Services;;
6、jquery之get,post,ajax:http://www.cnblogs.com/mqingqing123/archive/2009/10/16/1584727.html
7、js中this只的是調用函數的那個對象;
8、js中call和apply的區別:對於apply和call兩者在作用上是相同的,但兩者在參數上有區別的。
 對於第一個參數意義都一樣,但對第二個參數:
 apply傳入的是一個參數數組,也就是將多個參數組合成爲一個數組傳入,而call則作爲call的參數傳入(從第二個參數開始)。
 如 func.call(func1,var1,var2,var3)對應的apply寫法爲:func.apply(func1,[var1,var2,var3])
 同時使用apply的好處是可以直接將當前函數的arguments對象作爲apply的第二個參數傳入
9、object的實例不能訪問prototype屬性
10、在asp.net配置文件中authorization(授權)和authentication(認證)拼寫不要錯;
11、js的一個簡單結構:
 //定義空父類(負責定義函數)
        window.abstractCookie = {};
        abstractCookie.init = function () {
            //TODO:
            return this;
        };
        //父類函數
        abstractCookie.set = function () {
            alert(today.getTime());
            document.cookie = this.key + "=" + escape(this.value) + ";";
        };
        abstractCookie.get = function () {
            var begin = document.cookie.indexOf(this.key);
            if (begin == -1) return null;

            begin = this.key.length + 1;
            var end = document.cookie.indexOf(";", begin);
            if (end == -1) {
                end = document.cookie.length;
            }
            var val = document.cookie.substring(begin, end);
            return unescape(val);
        };
 //定義子類(只負責賦值)
        window.Tcookie = function (options) {
            this.key =options.key || "usrkey";
            this.value =options.value || "usrvalue";           
        };
        jQuery.extend(Tcookie.prototype, abstractCookie); //繼承abstractCookie
 //傳說中的靜態函數
        window.Tcookie.create = function () {
            var inst = new Tcookie(option);
            return inst.init();
        };
        jQuery(function () {
            var options = {key:"username",value:"glm"};
            var cook = new Tcookie(options);
            cook.set();
            if (cook.get() != "") {
                alert("welcome back " + cook.get());
            }
        });

12、var arr = XX.match(****);返回的數組arr[0]是完整匹配結果,其餘的爲子表達式匹配結果;

   子表達式允許嵌套,而且允許多層嵌套,嵌套層次在理論上沒有限制。
     在表達式 ((A)(B(C))) 中,存在以下幾個子表達式:
    ((A)(B(C)))
    (A)
    (B(C))
    (C)
 共4個,第0個始終代表整個表達式。在後面的回溯引用中會介紹到通過\n(n是子表式的編號)來引用子表達式。
13、npoi是導出excel,word,ppt到本地的好幫手,沒有安裝office的要求;
14、profile比session要強很多;
15、工廠模式、策略者模式、觀察者模式;
16、JQuery獲取標籤名居然是這樣jQuery("a").attr("tagName");
17、前臺獲取session的值,在jQuery(function(){})中獲取到了;
18、js獲取服務器控件:document.getElementById('<%=TextBox1.ClientID %>')
        jquery:jQuery('#'+'<%=TextBox1.ClientID %>').val(val);
19、ie不能識別firstChild.nodeValue,火狐不能識別innerText;
20、頁面使用了ScriptManager,則js循環獲取後臺的變量<%=data %>,如果頁面不回發,是獲取不到更新的值的。(可以用$.ajax解決)
21、修改了配置文件就可以使用Profile了:http://blog.csdn.net/adenfeng/article/details/5600830
   <system.web>
  <compilation debug="true" targetFramework="4.0"/>
    <authentication mode="Forms"/>
    <anonymousIdentification enabled="true"/>
    <profile>
      <properties>
        <add name="FirstName" defaultValue="??" allowAnonymous="true"/>
        <add name="LastName" defaultValue="??" allowAnonymous="true"/>
        <add name="PageVisits" type="Int32" allowAnonymous="true"/>
      </properties>
    </profile>
 </system.web>
22、異步調用IAsyncResult的使用:http://www.cnblogs.com/inforasc/archive/2009/10/21/1587756.html
23、在靜態函數中更新控件內容:
頁面類傳委託,靜態類通過委託更新,比如
class MyClass
{
    public static void foo(Action<string> OnUpdateText)
    {
        ...
        OnUpdateText("hello world");
    }
}

頁面類調用
class Default : Page
{
    public void Page_Load()
    {
        MyClass.foo(s => textBox1.Text = s);
    }
}
24、如果想讓Timer只更新一個控件,需要把此控件用UpdatePanel套住,然後外層的UpdatePanel屬性UpdateMode=conditional,ChildrenAsTriggers=false;
25、button點擊時,先執行前臺代碼,後執行後臺代碼:在page_Load事件中button.Attribute.add("onclick","return jsfunc");注意jsfunc一定要返回true;否則後臺就不執行了。
26、顯示星期幾:DateTime.Now.ToString("dddd", new System.Globalization.CultureInfo("zh-cn"))
27、正則表達式非獲取匹配、獲取匹配、正向預查、負正向預查、反向預查、負反向預查
28、常用泛型委託Action<T>,Func<T>,Predicate<T>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章