




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、jQuery對象的構建從其原理可以看出,其統一的入口就是jQuery對象。那么這個對象是如何生成的呢? jQuery的實質是Query,那么生成jQuery對象就可能看作是構建并運行一個查詢器。既然是查詢,肯定會有查找到的結果(Dom元素),那么這些結果又存放在 哪里呢?最好的地方當然是jQuery對象內面。查詢的結果可能是單個元素,也可能是集合如NodeSet。也就是說jQuery對象內面應該有一個集合。且這個集合是用來存 放查詢到Dom元素。但jQuery對象是所有操作的統一入口,那么它的構建就不應只局限 于從Dom文檔樹中查詢到Dom元素,有可能是從別的集合中轉移過來的Dom 元素,或是
2、html的片斷生成的Dom元素。Jquery 文檔中提供 了 四種構建方式:jQuery(expression,context), jQuery(html),jQuery(elements),jQuery(callback)。其中 jQuery 可以用$代替。這 四種方式是經常用到。其實Jquery的參數可以是任何的元素。也就是說任何的 參數都可以構建jquery對象。舉幾個例子:1、$($( “P”)可以看出其參數可以是jQuery對象或ArrayLike的集合。2、$()是$(document)的簡寫。3、$(3)會把3放到jQuery對象中集合中。對于如$(3)這樣的其中元素(如Arra
3、yLike集合的元素)不是Dom元素,最 好不要構建jQuery對象,jQuery對象的方法設計的目的都是針對于dom對象的 而進行的操作。如果不清楚其使用的話,很有可能會導致錯誤。上面講了這么多大道理,現在從源碼的角度細細分析:通過jQuery(xxx)的調用實現沒有生成對象,它的this是指向window對象的。那么jQuery的那些實例方法是怎樣繼承過來的呢?看一下:var jQuery = window.jQuery = window,$ =function(selector, context) (returnnew jQuery.fn.init(selector, context);
4、這是jquery的總入口,jQuery對象不是通過new jQuery來繼承其prototype中的方法,而是jQuery.fn.init函數生成的對象。這里我們可以看出對于jQtotype添加一些函數集的對象的意義不大。new jQuery()還是可以的,但是生成的jQuery對象在return時會被拋棄。故不要 用new jQuery()來構建jQuery對象。jQuery 對象其實就是 jQuery.fn.init 對象。那么 jQtotype 上就是掛著jQuery對象的操作方法。如jQtotype = jQuery.fn;有時間可能會擔心在589行就實現了把jQuery.fn中的函數
5、放到jQtotype上去, 那么之后的通過jquery.fn.extend的方法怎么辦呢?這里是對jQuery.fn的引用。在擴展jQuery的時候,只要把相關的函數extend到jQuery.fn 就可以了。現在我們看一下jQuery.fn.init是怎么完成工作的:init :function(selector, context) (selector = selector | document;/定 selector 存在/第一種情況Handle $(DOMElement)單個Dom元素,忽略上下文if (selector.nodeType) (this0 = selector;this.
6、length = 1;returnthis;if (typeof selector =string) (/selector 為 stringvar match = quickExpr.exec(selector);if (match & (match1 II !context)(if (match1)/第 二種情況處理 $(html) - $(array)selector = jQuery.clean(match1, context);else (/第三種情況:HANDLE: $(#id)/處理$(#id)var elem = document.getElementById(match3);i
7、f(elem) (/ IE會返回name=id的元素,如果是這樣,就document.find(s)if (elem.id != match3)return jQuery().find(selector);構建一個新的jQuery(elem)return jQuery(elem);selector =; else/第四種情況:處理 $(expr, context)=$(content).find(expr) TOC o 1-5 h z return jQuery(context).find(selector); elseif (jQuery.isFunction(selector)/第五種情況
8、:處理$(function)七 Shortcut for document readyreturn jQuery(document)jQuery.fn.ready ? ready : load(selector);/第六種情況:處理$(elements)returnthis.setArray(jQuery.makeArray(selector);,jQuery.fn.init負責對傳進來的參數進行分析然后生成jQuery對象。它的第一 個參數一般來說是必須的(為空的話,就是默認的document)。從源碼的角度第 一個參數有著如下四種類型:類型Dom /Element/String說明第一個參
9、數為Dom元素,第二個參數不用。直接把Dom元素存在新生成的jQuery對象的集合中。返回這個jQuery對象。構建jQuery對象完成。第一個參數為string有三種情況:1、html的標簽字符串,$(html) - $(array),第二個參數可選。執行 selector = jQuery.clean(match1, context)。該語句是把hteml的字符串轉換成dom對象的數組。接著執行Array類 型的返回。2、字符串為#id時$(id)首先通過 var elem = document.getElementById(match3)取得elem,如沒有取到selector =;轉到
10、執行Array類型的返回 空集合jquery對象。如找到elem,通過return jQuery(elem);再次生成jquery對象, 這次是Dom Element類型的jquery對象的返回。3、兼容css1-3語法的selector字符串,第二個參數是可選的。執行 return jQuery(context).find(selector);。該語句先執行 jQuery(context)。可以看出context第二參數可以是任意的值, 可以是集合形式。之后就通過find(selector)找到 jQuery(context)中所有dom 元素都滿足selector表達式的dom 元素的集合
11、,構建新的jquery對象,并返回。#id其實和這種方式是統一的,單獨出來是 為了提高性能。C+ Source Part OnekhmanagerView.cpp : implementation of the CKhmanagerView class#include stdafx.h#include khmanager.h#include khmanagerDoc.h#include khmanagerView.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endifCKh
12、managerViewIMPLEMENT_DYNCREATE(CKhmanagerView, CView) BEGIN_MESSAGE_MAP(CKhmanagerView, CView) AFX_MSG_MAP(CKhmanagerView) AFX_MSG_MAPStandard printing commandsON_COMMAND(ID_FILE_PRINT, CView:OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView:OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView:OnF
13、ilePrintPreview) END_MESSAGE_MAP()CKhmanagerView constructiondestructionCKhmanagerView:CKhmanagerView()CKhmanagerView:CKhmanagerView()BOOL CKhmanagerView:PreCreateWindow(CREATESTRUCT& cs)return CView:PreCreateWindow(cs);CKhmanagerView drawingvoid CKhmanagerView:OnDraw(CDC pDC)CKhmanagerDoc pDoc = Ge
14、tDocument();ASSERT_VALID(pDoc);CKhmanagerView printingBOOL CKhmanagerView:OnPreparePrinting(CPrintInfo pInfo)default preparationreturn DoPreparePrinting(pInfo);void CKhmanagerView:OnBeginPrinting(CDC pDC, CPrintInfo pInfo)void CKhmanagerView:OnEndPrinting(CDC pDC, CPrintInfo pInfo)CKhmanagerView dia
15、gnostics#ifdef _DEBUGvoid CKhmanagerView:AssertValid() constCView:AssertValid();void CKhmanagerView:Dump(CDumpContext& dc) constCView:Dump(dc);CKhmanagerDoc CKhmanagerView:GetDocument() non-debug version is inlineASSERT(m_pDocument-IsKindOf(RUNTIME_CLASS(CKhmanagerDoc);return (CKhmanagerDoc)m_pDocum
16、ent;#endif _DEBUGCKhmanagerView message handlersC+ Source Part Two#if !defined(AFX_OFFICER_H_DD010A11_0E5B_4762_B002_A3488892C751_INCLUDED_)#define AFX_OFFICER_H_DD010A11_0E5B_4762_B002_A3488892C751_INCLUDED_#if _MSC_VER 1000#pragma once#endif _MSC_VER 1000OFFICER.h : header fileCOFFICER dialogclass
17、 COFFICER : public CDialogConstructionpublic:COFFICER(CWnd pParent = NULL); standard constructor圖像數據參數與方法HBITMAPm_hPhotoBitmap;DWORDm_nFileLen;HBITMAPBufferToHBITMAP();BOOLLoadBMPFile(const char pBMPPathname);charm_pBMPBuffer;voidDestroyPhoto();voidDrawUserPhoto(int x,int y,CDC pDC);CBrush m_brush_s
18、tatic;labelCBrush m_brush_dlg;dlgDialog DataAFX_DATA(COFFICER)enum IDD = IDD_OFFICRER_DLG ;CString m_stroffjzlx;CString m_stroffsex;CString m_stroffzc;CString m_stroffzw;CTime m_timeoffbirth;CString m_stroffid;CString m_stroffjiguan;CString m_stroffjzbh;CString m_strofflxdz;CString m_stroffminzu;CSt
19、ring m_stroffmark;CString m_stroffname;CString m_stroffphone;CString m_stroffpostcode;CString m_stroffzjh;CString m_stroffzsdz;AFX_DATAOverridesClassWizard generated virtual function overridesAFX_VIRTUAL(COFFICER)protected:virtual void DoDataExchange(CDataExchange pDX); DDXDDV support AFX_VIRTUALImp
20、lementationprotected:Generated message map functionsAFX_MSG(COFFICER)afx_msg void OnButtonZyTijiao();afx_msg void OnButtonJlLoadphoto();afx_msg void OnPaint();virtual BOOL OnInitDialog();afx_msg HBRUSH OnCtlColor(CDC pDC, CWnd pWnd, UINT nCtlColor);AFX_MSGDECLARE_MESSAGE_MAP();AFX_INSERT_LOCATIONMic
21、rosoft Visual C+ will insert additional declarations immediately before the previous line.#endif !defined(AFX_OFFICER_H_DD010A11_0E5B_4762_B002_A3488892C751_INCLUDED_)C+ Source Part Three#if !defined(AFX_DLGPURVIEW_H_9BCBBC19_B958_11D7_A240_5254AB3E4F7E_INCLUDED_)#defineAFX_DLGPURVIEW_H_9BCBBC19_B95
22、8_11D7_A240_5254AB3E4F7E_INCLUDED_#if _MSC_VER 1000#pragma once#endif _MSC_VER 1000DlgPurview.h : header file#include myfunction.hCDlgPurview dialogclass CDlgPurview : public CDialogConstructionpublic:CDlgPurview(CWnd pParent = NULL); standard constructorDialog DataAFX_DATA(CDlgPurview)enum IDD = ID
23、D_DIALOG_XIUGAI_PURVIEW ;CButton m_btnXitong;CButton m_btnJichuxinxi;CButton m_btnZhangmu;CButton m_btnCaiwu;CButton m_btnDiaohuo;CButton m_btnKucun;CButton m_btnRuku;CButton m_btnXiaoshou;int m_iPurview;BOOL m_bXiaoshou;BOOL m_bRuku;BOOL m_bKucun;BOOL m_bDiaohuo;BOOL m_bCaiwu;BOOL m_bZhangmu;BOOL m
24、_bJichuxinxi;BOOL m_bXitong;AFX_DATAint m_iOldPurview;int m_iNewPurview;LRunSql m_runsql;OverridesClassWizard generated virtual function overrides(AFX_VIRTUAL(CDlgPurview)protected:virtual void DoDataExchange(CDataExchange pDX); DDXDDV supportAFX_VIRTUALImplementationprotected:void ChangeData(int pu
25、rview,CString field,bool b_value);void GetDataFromDatabase(int purview);void RefreshData(int purview);Generated message map functionsAFX_MSG(CDlgPurview)virtual BOOL OnInitDialog();virtual void OnOK();afx_msg void OnRadio1();afx_msg void OnRadio2();afx_msg void OnRadio3();afx_msg void OnRadio4();afx
26、_msg void OnCheck2();afx_msg void OnCheck3();afx_msg void OnCheck5();afx_msg void OnCheck6();afx_msg void OnCheck7();afx_msg void OnCheck8();afx_msg void OnCheck9();afx_msg void OnCheck10();AFX_MSGDECLARE_MESSAGE_MAP();AFX_INSERT_LOCATIONMicrosoft Visual C+ will insert additional declarations immedi
27、ately before the previous line.#endif !defined(AFX_DLGPURVIEW_H_9BCBBC19_B958_11D7_A240_5254AB3E4F7E_ INCLUDED_)C+ Source Part Foural.cpp : Defines the class behaviors for the application.#include stdafx.h#include a1.h#include a1Dlg.h#include MyFrame.h#include ScrollPrintDoc.h#include ScrollPrintVie
28、w.h#include myfunction.h#include DlgLogin.h#ifdef _DEBUG#include TRACEWIN.H#endif#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endifCA1AppBEGIN_MESSAGE_MAP(CA1App, CWinApp)(AFX_MSG_MAP(CA1App)AFX_MSG_MAPON_COMMAND(ID_HELP, CWinApp:OnHelp)ON_COMMAND( ID_FILE_PRINT_
29、SETUP, OnFilePrintSetup ) END_MESSAGE_MAP()CA1App constructionCA1App:CA1App()TODO: add construction code here,Place all significant initialization in InitInstancethis-m_sUserName;this-m_sPurview=0;The one and only CA1App objectCA1App theApp;CA1App initializationBOOL CA1App:InitInstance()CG : Initial
30、ize OLE librariesif (!AfxOleInit()AfxMessageBox(_T(OLE initialization failed.); return FALSE;AfxEnableControlContainer();Standard initializationIf you are not using these features and wish to reduce the size of your final executable, you should remove from the following the specific initialization r
31、outines you do not need.#ifdef _AFXDLLEnable3dControls();Call this when using MFC in a shared DLL#elseEnable3dControlsStatic(); Call this when linking to MFC statically #endif#ifdef _DEBUGCMfxTrace:Init();#endifthis-SetRegistryKey(進銷存管理系統”);WriteProfileInt(Settings”, x”, 23);WriteProfileInt(Settings
32、”, y”, 12);WriteProfileInt(Settings”, cx, 32);WriteProfileInt(Settings”, cy, 1233);WriteProfileInt(Settings, TraceWhere, 23);if(LRunSql:InitConnectPtr()=false) 初始化 COM 環境,進行數據庫連接 return false;pDocTemplate = new LSingleDocTemplate(IDR_MENU_MYFRAME,RUNTIME_CLASS(CScrollPrintDoc),RUNTIME_CLASS(CMyFrame
33、), main SDI frame window RUNTIME_CLASS(CScrollPrintView);AddDocTemplate(pDocTemplate);CMemoryState mem;mem.Checkpoint();CDlgLogin dlg;創建登錄窗口對象if(dlg.DoModal()=IDOK)顯示登錄窗口CAlDlg pdlg=new CAlDlg;創建主窗口對象 m_pMainWnd = pdlg;pdlg-DoModal(); 顯示主窗口delete pdlg;pdlg=NULL;mem.DumpAllObjectsSince();LRunSql:Clos
34、e();斷開數據庫連接Since the dialog has been closed, return FALSE so that we exit theapplication, rather than start the applications message pump.return FALSE;C+ Source Part FiveResetdatabase.cpp : implementation file#include stdafx.h#include Myhotel.h#include Resetdatabase.h#ifdef _DEBUG#define new DEBUG_N
35、EW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endifextern CMyhotelApp theApp;CResetdatabase dialogCResetdatabase:CResetdatabase(CWnd pParent =NULL):CDialog(CResetdatabase:IDD, pParent) (AFX_DATA_INIT(CResetdatabase)m_resetguazhang = FALSE;m_resetcheckoutreg = FALSE;m_resetcheckinreg = FALSE;m_re
36、setroombook = FALSE;m_resetroomstate = FALSE;AFX_DATA_INITvoid CResetdatabase:DoDataExchange(CDataExchange pDX)CDialog:DoDataExchange(pDX);AFX_DATA_MAP(CResetdatabase)DDX_Check(pDX, IDC_CHECKresetguazhang, m_resetguazhang);DDX_Check(pDX, IDC_CHECKresetcheckoutreg, m_resetcheckoutreg);DDX_Check(pDX,
37、IDC_CHECKresetcheckinreg, m_resetcheckinreg);DDX_Check(pDX, IDC_CHECKresetroombook, m_resetroombook);DDX_Check(pDX, IDC_CHECKresetroomstate, m_resetroomstate);AFX_DATA_MAPBEGIN_MESSAGE_MAP(CResetdatabase, CDialog)AFX_MSG_MAP(CResetdatabase)ON_BN_CLICKED(ID_beginresetdatabase, Onbeginresetdatabase)AF
38、X_MSG_MAPEND_MESSAGE_MAP()CResetdatabase message handlersvoid CResetdatabase:Onbeginresetdatabase()TODO: Add your control notification handler code here使輸入框可以接收輸入GetDlgItem(IDOK)-EnableWindow(1);GetDlgItem(IDC_groupdatabase)-EnableWindow(1);GetDlgItem(IDC_CHECKresetguazhang)-EnableWindow(1);GetDlgIt
39、em(IDC_CHECKresetcheckoutreg)-EnableWindow(1);GetDlgItem(IDC_CHECKresetcheckinreg)-EnableWindow(1);GetDlgItem(IDC_CHECKresetroombook)-EnableWindow(1);GetDlgItem(IDC_CHECKresetroomstate)-EnableWindow(1);BOOL CResetdatabase:OnInitDialog()CDialog:OnInitDialog();TODO: Add extra initialization here初始化各個輸
40、入框狀態GetDlgItem(IDOK)-EnableWindow(0);GetDlgItem(IDC_CHECKresetguazhang)-EnableWindow(0);GetDlgItem(IDC_CHECKresetcheckoutreg)-EnableWindow(0);GetDlgItem(IDC_CHECKresetcheckinreg)-EnableWindow(0);GetDlgItem(IDC_CHECKresetroombook)-EnableWindow(0);GetDlgItem(IDC_CHECKresetroomstate)-EnableWindow(0);Ge
41、tDlgItem(IDC_groupdatabase)-EnableWindow(0);return TRUE; return TRUE unless you set the focus to a controlEXCEPTION: OCX Property Pages should return FALSE void CResetdatabase:OnOK()TODO: Add extra validation here獲取輸入框內的數據UpdateData(true);m_pRecordset.CreateInstance(_uuidof(Recordset);if(m_resetroom
42、book)AfxMessageBox(wwwwww!);在ADO操作中建議語句中要常用try.catch()來捕獲錯誤信息,CString strsql;strsql.Format(DELETE FROM kfyd);try執行SQL語句,先打開數據表然后清空數據表m_pRecordset-Open(_variant_t)(strsql),查詢表中所有字段theApp.m_pConnection.GetInterfacePtr(),獲取庫接庫的IDispatch 指針adOpenDynamic, adLockOptimistic, adCmdText);MessageBox(成功初始化客房預定
43、登記表!”,”客房管理系統”);catch(_com_error。)拋出異常情況,因該過程可能有異常出現AfxMessageBox(e-ErrorMessage();m_pRecordset-Close();m_pRecordset = NULL;m_pRecordsetin.CreateInstance(_uuidof(Recordset);if(m_resetcheckinreg)AfxMessageBox(wwwwww!);在ADO操作中建議語句中要常用try.catch()來捕獲錯誤信息,CString strsql;strsql.Format(DELETE FROM checkinr
44、egtable);try執行SQL語句,先打開數據表然后清空數據表m_pRecordsetin-Open(_variant_t)(strsql),查詢表中所有字段theApp.m_pConnection.GetInterfacePtr(), 獲取庫接庫的 IDispatch 指針adOpenDynamic, adLockOptimistic, adCmdText);MessageBox(成功初始化住宿登記表!”,”客房管理系統); catch(_com_error。)拋出異常情況,因該過程可能有異常出現 AfxMessageBox(e-ErrorMessage();m_pRecordset-Close();m_pRecordsetin = NULL;m_pRecordsetout.CreateInstance(_uuidof(Recordset);if(m_resetche
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 生物質能源在建筑材料的研發與應用考核試卷
- 影視錄放設備的D打印技術應用考核試卷
- 初中數學聽課記錄
- 小學一年級下冊數學100以內口算綜合集錦
- 臨床肝膽胰脾影像診斷
- 上海紐約大學《亞洲地理及歷史》2023-2024學年第二學期期末試卷
- 四川省攀枝花市鹽邊縣2024-2025學年三下數學期末教學質量檢測模擬試題含解析
- 湘南學院《錄音藝術與聲音剪輯》2023-2024學年第一學期期末試卷
- 石家莊幼兒師范高等專科學校《工程分析程序設計》2023-2024學年第二學期期末試卷
- 山西省太原市2024-2025學年五下數學期末經典試題含答案
- 環境突發事件應急預案演練記錄
- 定期清洗消毒空調及通風設施制度
- 實戰經驗:2024年記者證考試試題及答案
- 無線電基礎知識培訓課件
- 投資咨詢工程師項目后評價試題及答案
- 4.1 基因指導蛋白質的合成(課件)高一下學期生物人教版(2019)必修2
- 醫療器械質量管理體系制度
- 人教版中職數學拓展模塊一:6.2復數的運算課件(共24張課件)
- 出租車司機崗前教育培訓
- 廣東省梅州市五華縣2023-2024學年二年級下學期數學期中試卷(含答案)
- 《水土保持監測技術規范SLT 277-2024》知識培訓
評論
0/150
提交評論