KDComboBox.htc 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  1. <!--/******************************************************************
  2. ** 文件名: KDComboBox.htc
  3. ** Copyright (c) 2005 金蝶国际软件集团有限公司 研发中心
  4. ** http://www.kingdee.com
  5. **
  6. ** 创建人: 叶汉良
  7. ** 日 期: 2005.06.01
  8. **
  9. ** 描述:下拉选择框控件
  10. ** 版 本:Web V1.0
  11. ******************************************************************/-->
  12. <public:component tagName="KDComboBox">
  13. <public:attach event="oncontentready" onevent="kdComboBoxReady()" />
  14. <public:attach event="onpropertychange" onevent="kdComboBoxPropertyChange()"/>
  15. <public:event name="onEvtIndexChange" id="evtIndexChange"/>
  16. <public:event name="onEvtClick" id="evtClick"/>
  17. <public:event name="onEvtDblClick" id="evtDblClick"/>
  18. <public:event name="onEvtMouseDown" id="evtMouseDown"/>
  19. <public:event name="onEvtMouseUp" id="evtMouseUp"/>
  20. <public:event name="onEvtMouseOver" id="evtMouseOver"/>
  21. <public:event name="onEvtMouseOut" id="evtMouseOut"/>
  22. <public:event name="onEvtMouseMove" id="evtMouseMove"/>
  23. <public:event name="onEvtFocus" id="evtFocus"/>
  24. <public:event name="onEvtBlur" id="evtBlur"/>
  25. <public:event name="onEvtKeyDown" id="evtKeyDown"/>
  26. <public:event name="onEvtKeyUp" id="evtKeyUp"/>
  27. <public:event name="onEvtKeyPress" id="evtKeyPress"/>
  28. <public:event name="onEvtChange" id="evtChange"/>
  29. <public:event name="onEvtBeforePaste" id="evtBeforePaste"/>
  30. <public:event name="onEvtSelectStart" id="evtSelectStart"/>
  31. <public:property name="initializeBorderColor" value="#B4B4B4"/>
  32. <public:property name="initializeBGColor" value="#FFFFFF"/>
  33. <public:property name="initializeTextFontColor" value="#000000"/>
  34. <public:property name="focusBorderColor" value="#5C85B3"/>
  35. <public:property name="focusBGColor" value="#255EA2"/>
  36. <public:property name="focusTextFontColor" value="#FFFFFF"/>
  37. <public:property name="readonlyBorderColor" value="#B4B4B4"/>
  38. <public:property name="readonlyBGColor" value="#FFFFFF"/>
  39. <public:property name="readonlyTextFontColor" value="#777777"/>
  40. <public:property name="disableBorderColor" value="#B4B4B4"/>
  41. <public:property name="disableBGColor" value="#D9D9D0"/>
  42. <public:property name="disableTextFontColor" value="#777777"/>
  43. <public:property name="mustBorderColor" value="#B4B4B4"/>
  44. <public:property name="mustBGColor" value="#FCFBDF"/>
  45. <public:property name="mustTextFontColor" value="#000000"/>
  46. <public:property name="width" value="170"/>
  47. <public:property name="height" value="19"/>
  48. <public:property name="dropHeight" value=""/>
  49. <public:property name="useDropHeight" value="false"/>
  50. <public:property name="cellHeight" value="16"/>
  51. <public:property name="readonly" value="false"/>
  52. <public:property name="disable" value="false"/>
  53. <public:property name="canEdit" value="false"/>
  54. <public:property name="mustInput" value="false"/>
  55. <public:property name="mustInputMsg" value=""/>
  56. <public:property name="name" value=""/>
  57. <public:property name="value" value=""/>
  58. <public:property name="id" value=""/>
  59. <public:property name="IDName" value=""/>
  60. <public:property name="IDValue" value=""/>
  61. <public:property name="maxLength" value=""/>
  62. <public:property name="fontSize" value="9pt"/>
  63. <public:property name="fontFamily" value="宋体"/>
  64. <public:property name="tabIndex1" value=""/>
  65. <public:property name="imagePath" value="../images/"/>
  66. <public:property name="cssPath" value=""/>
  67. <public:property name="tips" value=""/>
  68. <public:property name="align" value="left"/>
  69. <public:property name="iconWidth" value="18"/>
  70. <public:method name="focus"/>
  71. <public:method name="loadXML"/>
  72. <public:method name="addItem"/>
  73. <public:method name="insertItem"/>
  74. <public:method name="delItem"/>
  75. <public:method name="clearItems"/>
  76. <public:method name="updateItem"/>
  77. <public:method name="getCount"/>
  78. <public:method name="getSelectedIndex"/>
  79. <public:method name="setSelectedIndex"/>
  80. <public:method name="getIndexByID"/>
  81. <public:method name="getIndexByDesc"/>
  82. <public:method name="getItemID"/>
  83. <public:method name="setItemID"/>
  84. <public:method name="getItemDesc"/>
  85. <public:method name="setItemDesc"/>
  86. <public:method name="getItemData"/>
  87. <public:method name="setItemData"/>
  88. <script language="Javascript">
  89. var sTable = "<table border=0 style='table-layout:fixed;display:inline;' cellspacing=0 cellpadding=0>";
  90. var sListDiv = "<div style='border-style:solid;border-width:0;>";
  91. var sListTable = "<table style='table-layout:fixed;' border='0' cellpadding='1' cellspacing='1'>";
  92. var sInput = "<input type='text' style='border-width:0;padding-left:3;'>";
  93. var sHidden = "<input type='hidden' value=''>";
  94. var oTableE;
  95. var oTdInputE;
  96. var oTdDropE;
  97. var oImgE;
  98. var oInputE;
  99. var oHiddenE;
  100. var oListDivE = window.document.createElement(sListDiv);
  101. var oListTableE = window.document.createElement(sListTable);
  102. var sImageInit = "";
  103. var sImageForbit = "";
  104. var sImageDrop = "";
  105. //下拉菜单是否已经打开
  106. var isOpened = false;
  107. //弹出窗口
  108. var popWin = window.createPopup();
  109. //时间处理对象
  110. var oTimer = null;
  111. //当前选择的项
  112. var iSelectedIndex = -1;
  113. //是否全选
  114. var isSelectStart = false;
  115. /**
  116. *控件初始化
  117. *
  118. */
  119. function kdComboBoxReady()
  120. {
  121. initCss();
  122. var sItems = "";
  123. if (element.children(0).tagName == "ITEMS")
  124. {
  125. sItems = element.innerHTML;
  126. }
  127. else
  128. {
  129. sItems = element.itemHTML;
  130. }
  131. var sInnerHTML = "";
  132. sInnerHTML += sTable + "<tr>";
  133. sInnerHTML += "<td valign='top'>" + sInput + sHidden + "</td>";
  134. sInnerHTML += "<td><img></td>";
  135. sInnerHTML += "</tr></table>";
  136. element.innerHTML = sInnerHTML;
  137. element.itemHTML = sItems;
  138. oTableE = element.children(0);
  139. element.style.borderWidth = 0;
  140. oTableE.style.borderWidth = 1;
  141. oTableE.style.borderStyle = "solid";
  142. oTableE.style.width = width;
  143. //操作的左右单元格
  144. oTdInputE = element.children(0).rows(0).cells(0);
  145. oTdInputE.style.paddingTop = 0;
  146. oTdDropE = element.children(0).rows(0).cells(1);
  147. oInputE = oTdInputE.children(0);
  148. oHiddenE = oTdInputE.children(1);
  149. oImgE = oTdDropE.children(0);
  150. //初始化的时候的相关边框颜色设置
  151. oTableE.borderColor = initializeBorderColor;
  152. oTableE.style.backgroundColor = initializeBGColor;
  153. oTdInputE.style.width = width - iconWidth - 3;
  154. //表格有宽度,所以需要单元格高度-2
  155. oTdInputE.style.height = height - 2;
  156. oTdInputE.style.paddingLeft = 1;
  157. oTdDropE.style.width = iconWidth;
  158. oTdDropE.style.height = height - 2;
  159. oImgE.style.width = iconWidth;
  160. oImgE.style.height = height - 2;
  161. //不可用状态(注意不直接使用text的disabled属性,否则修改不了颜色
  162. if (eval(disable) == true)
  163. {
  164. oTableE.borderColor = disableBorderColor;
  165. oTableE.style.backgroundColor = disableBGColor;
  166. oInputE.style.backgroundColor = disableBGColor;
  167. oInputE.style.color = disableTextFontColor;
  168. //此处不使用disabled这个属性,否则文字的颜色无法进行修改
  169. oInputE.readOnly = true;
  170. oImgE.src = sImageForbit;
  171. oInputE.tabIndex = "";
  172. }
  173. else
  174. {
  175. //只读状态
  176. if (eval(readonly) == true)
  177. {
  178. oTableE.borderColor = readonlyBorderColor;
  179. oTableE.style.backgroundColor = readonlyBGColor;
  180. oInputE.style.backgroundColor = readonlyBGColor;
  181. oInputE.style.color = readonlyTextFontColor;
  182. oInputE.readOnly = true;
  183. }
  184. else
  185. {
  186. //初始状态
  187. if (eval(mustInput) == false)
  188. {
  189. oTableE.borderColor = initializeBorderColor;
  190. oTableE.style.backgroundColor = initializeBGColor;
  191. oInputE.style.backgroundColor = initializeBGColor;
  192. oInputE.style.color = initializeTextFontColor;
  193. }
  194. else
  195. {
  196. oTableE.borderColor = mustBorderColor;
  197. oTableE.style.backgroundColor = mustBGColor;
  198. oInputE.style.backgroundColor = mustBGColor;
  199. oInputE.style.color = mustTextFontColor;
  200. }
  201. //可编辑状态
  202. if (eval(canEdit) != true)
  203. {
  204. oInputE.readOnly = true;
  205. }
  206. }
  207. oImgE.src = sImageInit;
  208. oInputE.tabIndex = tabIndex1;
  209. }
  210. //向下偏移计算值的像素
  211. if (height >= 19)
  212. {
  213. oInputE.style.paddingTop = 2 + (height - 19) / 5;
  214. }
  215. oInputE.style.fontSize = fontSize;
  216. oInputE.value = value;
  217. oInputE.name = name;
  218. oInputE.id = id;
  219. oInputE.valueChanged = false;
  220. oInputE.isInit = true;
  221. oInputE.style.width = width - iconWidth - 4;
  222. oInputE.style.height = height - 4;
  223. oInputE.title = tips;
  224. oInputE.style.textAlign = align;
  225. oInputE.style.fontFamily = fontFamily;
  226. if (maxLength != null && maxLength != "")
  227. {
  228. element.children(0).maxLength = maxLength;
  229. }
  230. oHiddenE.name = IDName;
  231. oHiddenE.value = IDValue;
  232. loadXML(sItems,true);
  233. oListDivE.appendChild(oListTableE);
  234. doEvents();
  235. setPop(popWin.document.body);
  236. }
  237. /**
  238. *事件处理
  239. *
  240. */
  241. function doEvents()
  242. {
  243. oTableE.attachEvent("onclick",function(){execute("click")});
  244. oTableE.attachEvent("onmousedown",function(){execute("mousedown")});
  245. oTableE.attachEvent("onmouseover",function(){execute("mouseover")});
  246. oTableE.attachEvent("onmouseout",function(){execute("mouseout")});
  247. oTableE.attachEvent("onmouseup",function(){execute("mouseup")});
  248. oTableE.attachEvent("onmousemove",function(){execute("mousemove")});
  249. oTableE.attachEvent("onchange",function(){execute("change")});
  250. oTableE.attachEvent("oncontextmenu",function(){return false});
  251. oInputE.attachEvent("onfocus",function(){execute("focus")});
  252. oInputE.attachEvent("onblur",function(){execute("blur")});
  253. oInputE.attachEvent("onkeydown",function(){execute("keydown")});
  254. oInputE.attachEvent("onkeyup",function(){execute("keyup")});
  255. oInputE.attachEvent("onkeypress",function(){return execute("keypress")});
  256. oInputE.attachEvent("onselectstart",function(){return execute("selectstart")});
  257. oInputE.attachEvent("onbeforepaste",function(){return execute("beforepaste")});
  258. oInputE.attachEvent("ondblclick",function(){execute("dblclick")});
  259. }
  260. /**
  261. *属性值发生相关变化的时候处理方式
  262. *
  263. */
  264. function kdComboBoxPropertyChange()
  265. {
  266. switch(event.propertyName.toString().toLowerCase())
  267. {
  268. case "width":
  269. {
  270. oTableE.style.width = width;
  271. oTdInputE.style.width = width - iconWidth - 3;
  272. oInputE.style.width = width - iconWidth - 4;
  273. break;
  274. }
  275. case "height":
  276. {
  277. oTdInputE.style.height = height - 2;
  278. oInputE.style.height = height - 4;
  279. oImgE.style.height = height - 2;
  280. if (height >= 19)
  281. {
  282. oInputE.style.paddingTop = 3 + (height - 19) / 5;
  283. }
  284. else
  285. {
  286. oInputE.style.paddingTop = 0;
  287. }
  288. break;
  289. }
  290. //初始化颜色发生了变化
  291. case "initializebordercolor":
  292. {
  293. if (eval(disable) != true && eval(readonly) != true)
  294. {
  295. oTableE.borderColor = initializeBorderColor;
  296. }
  297. break;
  298. }
  299. case "initializebgcolor":
  300. {
  301. if (eval(disable) != true && eval(readonly) != true)
  302. {
  303. oInputE.style.backgroundColor = initializeBGColor;
  304. }
  305. break;
  306. }
  307. case "initializetextfontColor":
  308. {
  309. if (eval(disable) != true && eval(readonly) != true)
  310. {
  311. oInputE.style.color = initializeTextFontColor;
  312. }
  313. break;
  314. }
  315. //只读颜色发生了变化
  316. case "readonlybordercolor":
  317. {
  318. if (eval(disable) != true && eval(readonly) == true)
  319. {
  320. oTableE.borderColor = readonlyBorderColor;
  321. }
  322. break;
  323. }
  324. case "readonlybgcolor":
  325. {
  326. if (eval(disable) != true && eval(readonly) == true)
  327. {
  328. oInputE.style.backgroundColor = readonlyBGColor;
  329. }
  330. break;
  331. }
  332. case "readonlytextfontcolor":
  333. {
  334. if (eval(disable) != true && eval(readonly) == true)
  335. {
  336. oInputE.style.color = readonlyTextFontColor;
  337. }
  338. break;
  339. }
  340. //disable的时候颜色发生了变化
  341. case "disablebordercolor":
  342. {
  343. if (eval(disable) == true)
  344. {
  345. oTableE.borderColor = disableBorderColor;
  346. }
  347. break;
  348. }
  349. case "disablebgcolor":
  350. {
  351. if (eval(disable) == true)
  352. {
  353. oInputE.style.backgroundColor = disableBGColor;
  354. }
  355. break;
  356. }
  357. case "disabletextfontcolor":
  358. {
  359. if (eval(disable) == true)
  360. {
  361. oInputE.style.color = disableTextFontColor;
  362. }
  363. break;
  364. }
  365. //值发生了变化
  366. case "value":
  367. {
  368. doValueChange();
  369. break;
  370. }
  371. //只读发生了变化
  372. case "readonly":
  373. {
  374. if (eval(disable) != true)
  375. {
  376. //变化为只读状态
  377. if (eval(readonly) == true)
  378. {
  379. oTableE.borderColor = readonlyBorderColor;
  380. oTableE.style.backgroundColor = readonlyBGColor;
  381. oInputE.style.backgroundColor = readonlyBGColor;
  382. oInputE.style.color = readonlyTextFontColor;
  383. oInputE.readOnly = true;
  384. }
  385. else
  386. {
  387. oTableE.borderColor = initializeBorderColor;
  388. oTableE.style.backgroundColor = initializeBGColor;
  389. oInputE.style.backgroundColor = initializeBGColor;
  390. oInputE.style.color = initializeTextFontColor;
  391. oInputE.readOnly = false;
  392. }
  393. }
  394. break;
  395. }
  396. //不可使用发生了变化
  397. case "disable":
  398. {
  399. if (eval(disable) == true)
  400. {
  401. oTableE.borderColor = disableBorderColor;
  402. oTableE.style.backgroundColor = disableBGColor;
  403. oInputE.style.backgroundColor = disableBGColor;
  404. oInputE.style.color = disableTextFontColor;
  405. oTdDropE.children(0).src = sImageForbit;
  406. oInputE.readOnly = true;
  407. oInputE.tabIndex = "";
  408. }
  409. else
  410. {
  411. //变化为只读状态
  412. if (eval(readonly) == true)
  413. {
  414. oTableE.borderColor = readonlyBorderColor;
  415. oTableE.style.backgroundColor = readonlyBGColor;
  416. oInputE.style.backgroundColor = readonlyBGColor;
  417. oInputE.style.color = readonlyTextFontColor;
  418. oInputE.readOnly = true;
  419. }
  420. else
  421. {
  422. if (eval(mustInput) == true)
  423. {
  424. oTableE.borderColor = mustBorderColor;
  425. oTableE.style.backgroundColor = mustBGColor;
  426. oInputE.style.backgroundColor = mustBGColor;
  427. oInputE.style.color = mustTextFontColor;
  428. }
  429. else
  430. {
  431. oTableE.borderColor = initializeBorderColor;
  432. oTableE.style.backgroundColor = initializeBGColor;
  433. oInputE.style.backgroundColor = initializeBGColor;
  434. oInputE.style.color = initializeTextFontColor;
  435. }
  436. if (eval(canEdit) == true)
  437. {
  438. oInputE.readOnly = false;
  439. }
  440. else
  441. {
  442. oInputE.readOnly = true;
  443. }
  444. }
  445. oTdDropE.children(0).src = sImageInit;
  446. oInputE.tabIndex = tabIndex1;
  447. }
  448. break;
  449. }
  450. case "fontsize":
  451. {
  452. oInputE.style.fontSize = fontSize;
  453. break;
  454. }
  455. case "tips":
  456. {
  457. oInputE.title = tips;
  458. }
  459. default:
  460. break;
  461. }
  462. }
  463. //执行相关的事件
  464. function execute(sEvent)
  465. {
  466. //不可处理状态下,不能进行处理
  467. if (eval(disable) == true || eval(readonly) == true)
  468. {
  469. return false;
  470. }
  471. if (sEvent == "click")
  472. {
  473. evtClick.fire();
  474. }
  475. else if (sEvent == "mouseup")
  476. {
  477. return doMouseUp();
  478. }
  479. else if (sEvent == "mousedown")
  480. {
  481. return doMouseDown();
  482. }
  483. else if (sEvent == "mousemove")
  484. {
  485. evtMouseMove.fire();
  486. }
  487. else if (sEvent == "mouseover")
  488. {
  489. evtMouseOver.fire();
  490. }
  491. else if (sEvent == "mouseout")
  492. {
  493. evtMouseOut.fire();
  494. }
  495. else if (sEvent == "keyup")
  496. {
  497. return doKeyUp();
  498. }
  499. else if (sEvent == "keydown")
  500. {
  501. return doKeyDown();
  502. }
  503. else if (sEvent == "keypress")
  504. {
  505. return doKeyPress();
  506. }
  507. else if (sEvent == "change")
  508. {
  509. evtChange.fire();
  510. }
  511. else if (sEvent == "beforepaste")
  512. {
  513. return doBeforePaste();
  514. }
  515. else if (sEvent == "selectstart")
  516. {
  517. return doSelectStart();
  518. }
  519. //可以修改边框的相关的颜色
  520. else if (sEvent == "focus")
  521. {
  522. oTableE.borderColor = focusBorderColor;
  523. oInputE.style.backgroundColor = focusBGColor;
  524. oInputE.style.color = focusTextFontColor;
  525. moveCursor(oInputE,oInputE.value.length);
  526. evtFocus.fire();
  527. }
  528. else if (sEvent == "blur")
  529. {
  530. if (eval(mustInput) == false)
  531. {
  532. oTableE.borderColor = initializeBorderColor;
  533. oInputE.style.backgroundColor = initializeBGColor;
  534. oInputE.style.color = initializeTextFontColor;
  535. }
  536. else
  537. {
  538. oTableE.borderColor = mustBorderColor;
  539. oInputE.style.backgroundColor = mustBGColor;
  540. oInputE.style.color = mustTextFontColor;
  541. if (oInputE.value == "" && mustInputMsg != "")
  542. {
  543. alert(mustInputMsg);
  544. }
  545. }
  546. evtBlur.fire();
  547. }
  548. else if (sEvent == "dblclick")
  549. {
  550. evtDblClick.fire();
  551. }
  552. }
  553. //得到焦点
  554. function focus()
  555. {
  556. if (eval(disable) == true)
  557. {
  558. return;
  559. }
  560. execute("focus");
  561. oInputE.focus();
  562. }
  563. /**
  564. *
  565. *处理鼠标按下的时候的事件
  566. */
  567. function doMouseDown()
  568. {
  569. oImgE.src = sImageDrop;
  570. if (isOpened)
  571. {
  572. popWin.hide();
  573. isOpened = false;
  574. return;
  575. }
  576. var oBody = popWin.document.body;
  577. oBody.innerHTML = oListDivE.outerHTML;
  578. popWin.show(getComLeft(element),getComTop(element),width,calcHeight(),window.document.body);
  579. popEvent(popWin);
  580. gotoCell(iSelectedIndex);
  581. oTimer = window.setInterval(onTimer,100);
  582. isOpened = true;
  583. evtMouseDown.fire();
  584. event.cancelBubble = true;
  585. return false;
  586. }
  587. /**
  588. *键盘keydown事件处理
  589. *
  590. */
  591. function doKeyDown()
  592. {
  593. var iOldIndex = iSelectedIndex;
  594. //索引是否发生改变
  595. var isIndexChange = false;
  596. var popTable = null;
  597. if (iSelectedIndex != -1)
  598. {
  599. popTable = getPopTable(popWin);
  600. if (popTable != null)
  601. {
  602. updateStyle(popTable.rows[iSelectedIndex].cells[0],initializeBGColor,initializeTextFontColor);
  603. }
  604. }
  605. switch (event.keyCode)
  606. {
  607. //Down
  608. case 40:
  609. if (getCount() != 0)
  610. {
  611. if (iSelectedIndex < getCount() - 1)
  612. {
  613. iSelectedIndex ++;
  614. }
  615. }
  616. else
  617. {
  618. iSelectedIndex = -1;
  619. }
  620. break;
  621. //Up
  622. case 38:
  623. if (getCount() != 0)
  624. {
  625. if (iSelectedIndex > 0)
  626. {
  627. iSelectedIndex --;
  628. }
  629. }
  630. else
  631. {
  632. iSelectedIndex = -1;
  633. }
  634. break;
  635. //Page Up
  636. case 33:
  637. if (getCount() != 0)
  638. {
  639. //向上滚动5行(如果达到最顶,则取第一项
  640. if (iSelectedIndex - 5 > 0)
  641. {
  642. iSelectedIndex -= 5;
  643. }
  644. else
  645. {
  646. iSelectedIndex = 0;
  647. }
  648. }
  649. else
  650. {
  651. iSelectedIndex = -1;
  652. }
  653. break;
  654. //Page Down
  655. case 34:
  656. if (getCount() != 0)
  657. {
  658. //向下滚动5行,如果到达尾,则取最后一项
  659. if (iSelectedIndex + 5 < getCount() -1)
  660. {
  661. iSelectedIndex += 5;
  662. }
  663. else
  664. {
  665. iSelectedIndex = getCount() - 1;
  666. }
  667. }
  668. else
  669. {
  670. iSelectedIndex = -1;
  671. }
  672. break;
  673. //End
  674. case 35:
  675. //在不可编辑状态下才支持end键操作
  676. if (canEdit == "false")
  677. {
  678. if (getCount() != 0)
  679. {
  680. iSelectedIndex = getCount() - 1;
  681. }
  682. else
  683. {
  684. iSelectedIndex = -1;
  685. }
  686. }
  687. break;
  688. //Home
  689. case 36:
  690. //在不可编辑下才支持home键操作
  691. if (canEdit == "false")
  692. {
  693. if (getCount() != 0)
  694. {
  695. iSelectedIndex = 0;
  696. }
  697. else
  698. {
  699. iSelectedIndex = -1;
  700. }
  701. }
  702. break;
  703. //Enter
  704. case 13:
  705. if (isOpened == true)
  706. {
  707. popWin.hide();
  708. isOpened = false;
  709. }
  710. break;
  711. //ESC
  712. case 27:
  713. if (isOpened == true)
  714. {
  715. popWin.hide();
  716. isOpened = false;
  717. }
  718. break;
  719. default:
  720. break;
  721. }
  722. //如果下拉列表已经打开,则需要把位置定在相关的位置上
  723. if (event.keyCode == 40 || event.keyCode == 38 || event.keyCode == 33 ||
  724. event.keyCode == 34 || event.keyCode == 35 || event.keyCode == 36 ||
  725. event.keyCode == 13 || event.keyCode == 27)
  726. {
  727. if (isOpened == true)
  728. {
  729. gotoCell(iSelectedIndex);
  730. }
  731. if (iSelectedIndex != -1)
  732. {
  733. //home,end键应该根据canEdit做特殊的处理
  734. if (event.keyCode == 35 || event.keyCode == 36)
  735. {
  736. if (canEdit == "false")
  737. {
  738. setSelectedItem(oListTableE.rows[iSelectedIndex].cells[0]);
  739. moveCursor(oInputE,oInputE.value.length);
  740. }
  741. }
  742. else
  743. {
  744. setSelectedItem(oListTableE.rows[iSelectedIndex].cells[0]);
  745. moveCursor(oInputE,oInputE.value.length);
  746. }
  747. }
  748. if (iOldIndex != iSelectedIndex)
  749. {
  750. isIndexChange = true;
  751. }
  752. }
  753. oInputE.oldValue = oInputE.value;
  754. evtKeyDown.fire();
  755. if (eval(canEdit) == false)
  756. {
  757. if (event.keyCode != 9)
  758. {
  759. event.returnValue = false;
  760. }
  761. }
  762. event.cancelBubble = true;
  763. //索引发生了变化,触发
  764. if (isIndexChange == true)
  765. {
  766. //索引发生了变化
  767. evtIndexChange.fire();
  768. //数据发生了变化
  769. evtChange.fire();
  770. }
  771. doEnterGo();
  772. }
  773. /**
  774. *键盘keyup处理
  775. *
  776. */
  777. function doKeyUp()
  778. {
  779. var iOldIndex = iSelectedIndex;
  780. //是否是控制键,up,down,home,end,enter,esc,page up,page down
  781. var isControlKey = true;
  782. var iCurPos = getCursorPosition();
  783. if (!(event.keyCode == 40 || event.keyCode == 38 || event.keyCode == 33 ||
  784. event.keyCode == 34 || event.keyCode == 35 || event.keyCode == 36 ||
  785. event.keyCode == 13 || event.keyCode == 27))
  786. {
  787. isControlKey = false;
  788. iSelectedIndex = getIndexByDesc(oInputE.value);
  789. }
  790. if (iSelectedIndex != -1)
  791. {
  792. setSelectedItem(oListTableE.rows[iSelectedIndex].cells[0],true);
  793. if (isOpened == true)
  794. {
  795. gotoCell(iSelectedIndex);
  796. }
  797. }
  798. else
  799. {
  800. oInputE.itemid = null;
  801. oInputE.desc = oInputE.value;
  802. oInputE.data = null;
  803. oInputE.selected = null;
  804. oInputE.valueChanged = true;
  805. oHiddenE.value = null;
  806. value = oInputE.value;
  807. }
  808. if (isControlKey == false && isSelectStart == false)
  809. {
  810. moveCursor(oInputE,iCurPos);
  811. isSelectStart = false;
  812. }
  813. evtKeyUp.fire();
  814. if (canEdit == "false")
  815. {
  816. event.returnValue = false;
  817. }
  818. event.cancelBubble = true;
  819. //非控制键发生变化的时候也需要处理索引变化事件
  820. if (isControlKey == false && iOldIndex != iSelectedIndex)
  821. {
  822. evtIndexChange.fire();
  823. }
  824. //数据发生了变化,数据变化处理事件
  825. if (isControlKey == false && oInputE.value != oInputE.oldValue)
  826. {
  827. evtChange.fire();
  828. }
  829. }
  830. /**
  831. *鼠标按键按着的时候处理事件
  832. *
  833. */
  834. function doKeyPress()
  835. {
  836. event.cancelBubble = true;
  837. evtKeyPress.fire();
  838. return true;
  839. }
  840. /**
  841. *value属性的值发生变化的时候处理的函数
  842. *
  843. */
  844. function doValueChange()
  845. {
  846. //加载KDComboBox的时候不处理doValueChange
  847. if (oInputE.isInit)
  848. {
  849. oInputE.isInit = false;
  850. return;
  851. }
  852. //如果先改变oInputE.value,则不能再次修改oInputE的值
  853. if (oInputE.valueChanged != true)
  854. {
  855. iSelectedIndex = getIndexByDesc(value);
  856. if (iSelectedIndex != -1)
  857. {
  858. var oCell = oListTableE.rows[iSelectedIndex].cells[0];
  859. oInputE.itemid = oCell.itemid;
  860. oInputE.desc = oCell.desc;
  861. oInputE.data = oCell.data;
  862. oInputE.selected = oCell.selected;
  863. oHiddenE.value = oCell.itemid;
  864. if (isOpened == true)
  865. {
  866. gotoCell(iSelectedIndex);
  867. }
  868. }
  869. else
  870. {
  871. oInputE.itemid = null;
  872. oInputE.desc = value;
  873. oInputE.data = null;
  874. oInputE.value = value;
  875. oInputE.selected = null;
  876. oHiddenE.value = null;
  877. }
  878. evtChange.fire();
  879. }
  880. oInputE.valueChange = false;
  881. }
  882. /**
  883. *处理粘贴前的动作
  884. *
  885. */
  886. function doBeforePaste()
  887. {
  888. if (eval(disable) == true || eval(readonly) == true || eval(canEdit) == false)
  889. {
  890. return false;
  891. }
  892. clipboardData.setData('text',clipboardData.getData('text'));
  893. iSelectedIndex = getIndexByDesc(oInputE.value);
  894. if (iSelectedIndex != -1)
  895. {
  896. setSelectedItem(oListTableE.rows[iSelectedIndex].cells[0],true);
  897. if (isOpened == true)
  898. {
  899. gotoCell(iSelectedIndex);
  900. }
  901. }
  902. else
  903. {
  904. oInputE.itemid = null;
  905. oInputE.desc = oInputE.value;
  906. oInputE.data = null;
  907. oInputE.selected = null;
  908. oInputE.valueChanged = true;
  909. oHiddenE.value = null;
  910. value = oInputE.value;
  911. }
  912. evtBeforePaste.fire();
  913. return true;
  914. }
  915. /**
  916. *选中某一块时的事件
  917. *
  918. */
  919. function doSelectStart()
  920. {
  921. evtSelectStart.fire();
  922. isSelectStart = true;
  923. if (canEdit == "false")
  924. {
  925. return false;
  926. }
  927. else
  928. {
  929. return true;
  930. }
  931. }
  932. /**
  933. *回车键的时候跳到其他焦点
  934. *
  935. */
  936. function doEnterGo()
  937. {
  938. if (event.keyCode == 13 && isOpened == false)
  939. {
  940. event.keyCode = 9;
  941. }
  942. }
  943. //处理鼠标放开的时候的事件
  944. function doMouseUp()
  945. {
  946. oImgE.src = sImageInit;
  947. if (event.srcElement.tagName == "IMG")
  948. {
  949. oInputE.focus();
  950. }
  951. evtMouseUp.fire();
  952. }
  953. function doMouseOut()
  954. {
  955. oImgE.src = sImageInit;
  956. evtMouseMove.fire();
  957. }
  958. /**
  959. *
  960. *定位到某个单元格
  961. *@rowId是表格行号
  962. */
  963. function gotoCell(rowIndex)
  964. {
  965. if (!oListDivE)
  966. {
  967. return false;
  968. }
  969. //非表格行
  970. if (!isTableRow(rowIndex))
  971. {
  972. return false;
  973. }
  974. var tbl = getPopTable(popWin);
  975. if (tbl == null)
  976. {
  977. return false;
  978. }
  979. if (tbl.tagName == "TABLE")
  980. {
  981. var oRow;
  982. var iTop;
  983. oRow = tbl.rows[rowIndex];
  984. updateStyle(oRow.cells[0],focusBGColor,focusTextFontColor);
  985. var iTop = oRow.offsetTop - element.scrollTop;
  986. if (iTop > 0 && (iTop + oRow.offsetHeight) > oListDivE.offsetHeight)
  987. {
  988. oRow.scrollIntoView(false);
  989. }
  990. else if (iTop <= 0)
  991. {
  992. oRow.scrollIntoView(true);
  993. }
  994. }
  995. }
  996. /**
  997. * rowId是否是表格中的行
  998. *
  999. */
  1000. function isTableRow(rowId)
  1001. {
  1002. if (!oListDivE)
  1003. {
  1004. return false;
  1005. }
  1006. var tbl = oListDivE.childNodes[0];
  1007. if (!tbl)
  1008. {
  1009. return false;
  1010. }
  1011. if (rowId >= 0 && rowId < tbl.rows.length)
  1012. {
  1013. return true;
  1014. }
  1015. else
  1016. {
  1017. return false;
  1018. }
  1019. }
  1020. /**
  1021. *得到控件oCom的绝对坐标x
  1022. *
  1023. */
  1024. function getComLeft(oCom)
  1025. {
  1026. var iLeft = 0;
  1027. while (oCom.offsetParent)
  1028. {
  1029. iLeft += oCom.offsetLeft - oCom.scrollLeft;
  1030. oCom = oCom.offsetParent;
  1031. }
  1032. iLeft += oCom.clientLeft - oCom.scrollLeft;
  1033. return iLeft;
  1034. }
  1035. /**
  1036. *得到控件oCom的绝对坐标y
  1037. *
  1038. */
  1039. function getComTop(oCom)
  1040. {
  1041. var iScrollTop;
  1042. var iTop = oCom.offsetTop;
  1043. var iCalcHight = calcHeight();
  1044. while (oCom.offsetParent)
  1045. {
  1046. iTop += oCom.offsetTop - oCom.scrollTop;
  1047. oCom = oCom.offsetParent;
  1048. }
  1049. iTop += oCom.clientTop - oCom.scrollTop;
  1050. //如果下拉的窗体超出了最底的显示宽度,则向上弹出列表
  1051. if (iTop + parseInt(height) + 3 + iCalcHight + window.screenTop > screen.height)
  1052. {
  1053. iTop = iTop - iCalcHight - 2;
  1054. }
  1055. else
  1056. {
  1057. iTop += parseInt(height);
  1058. }
  1059. return iTop;
  1060. }
  1061. /**
  1062. *时钟处理(目的为了能够在其他地方关闭了下拉列表的时候,能够把isOpened参数设置为false)
  1063. *
  1064. */
  1065. function onTimer()
  1066. {
  1067. if (popWin.isOpen == false)
  1068. {
  1069. isOpened = false;
  1070. window.clearInterval(oTimer);
  1071. }
  1072. }
  1073. /**
  1074. *加载数据,oData为对象,isClear表明是否清楚原来的数据
  1075. *
  1076. */
  1077. function loadData(oData,isClear)
  1078. {
  1079. if (!oData)
  1080. {
  1081. return;
  1082. }
  1083. if (isClear && isClear == true)
  1084. {
  1085. clearItems();
  1086. }
  1087. for (var i = 0; i < oData.length; i ++)
  1088. {
  1089. addItem(oData[i].itemid,oData[i].desc,oData[i].data,oData[i].selected);
  1090. }
  1091. }
  1092. /**
  1093. *往下来框中增加一项(itemID是标识本项,desc显示在下拉框中的信息,
  1094. *data为其他需要填充的信息,selected表示加入的是选择项)
  1095. *
  1096. */
  1097. function addItem(itemID,desc,data,selected)
  1098. {
  1099. var oRow = oListTableE.insertRow();
  1100. var oCell = oRow.insertCell();
  1101. setCellProperty(oCell,itemID,desc,data,selected);
  1102. if (selected && eval(selected) == true)
  1103. {
  1104. iSelectedIndex = oRow.rowIndex;
  1105. setSelectedItem(oListTableE.rows[iSelectedIndex].cells[0]);
  1106. }
  1107. }
  1108. /**
  1109. *在index指定的索引前增加一项
  1110. *
  1111. */
  1112. function insertItem(index,itemID,desc,data,selected)
  1113. {
  1114. if (isTableRow(index) == false)
  1115. {
  1116. return;
  1117. }
  1118. var oRow = oListTableE.insertRow(index);
  1119. var oCell = oRow.insertCell();
  1120. setCellProperty(oCell,itemID,desc,data,selected);
  1121. if (selected && selected == true)
  1122. {
  1123. iSelectedIndex = oRow.rowIndex;
  1124. setSelectedItem(oListTableE.rows[iSelectedIndex].cells[0]);
  1125. }
  1126. }
  1127. /**
  1128. *设置单元格的属性
  1129. *
  1130. */
  1131. function setCellProperty(oCell,itemID,desc,data,selected)
  1132. {
  1133. oCell.itemid = itemID;
  1134. oCell.desc = desc;
  1135. oCell.data = data;
  1136. oCell.selected = selected;
  1137. oCell.innerHTML = "<font size='2'>" + desc + "</font>";
  1138. oCell.title = desc;
  1139. oCell.fontSize = "9px";
  1140. oCell.style.height = cellHeight;
  1141. oCell.style.paddingTop = 2;
  1142. oCell.style.cursor = "hand";
  1143. oCell.style.paddingLeft = 3;
  1144. oCell.style.backgroundColor = initializeBGColor;
  1145. oCell.style.color = initializeTextFontColor;
  1146. }
  1147. /**
  1148. *清空下拉框中的所有数据
  1149. *
  1150. */
  1151. function clearItems()
  1152. {
  1153. //这种处理速度比较快
  1154. for (var i = getCount() - 1; i >= 0; i --)
  1155. {
  1156. delItem(i);
  1157. }
  1158. //setNoSelectItem();
  1159. }
  1160. /**
  1161. *删除指定的项(index为需要删除的索引)
  1162. *
  1163. */
  1164. function delItem(index)
  1165. {
  1166. if (isTableRow(index) == false)
  1167. {
  1168. return;
  1169. }
  1170. if (isOpened == true)
  1171. {
  1172. isOpened = false;
  1173. popWin.hide();
  1174. }
  1175. oListTableE.deleteRow(index);
  1176. if (index == iSelectedIndex)
  1177. {
  1178. setNoSelectItem();
  1179. }
  1180. }
  1181. /**
  1182. *当没有选中的时候,设置空值
  1183. *
  1184. */
  1185. function setNoSelectItem()
  1186. {
  1187. iSelectedIndex = -1;
  1188. oInputE.itemID = null;
  1189. oInputE.desc = null;
  1190. oInputE.data = null;
  1191. oInputE.selected = null;
  1192. oInputE.value = "";
  1193. oHiddenE.value = null;
  1194. value = "";
  1195. }
  1196. /**
  1197. *得到下拉框的项数
  1198. *
  1199. */
  1200. function getCount()
  1201. {
  1202. return oListTableE.rows.length;
  1203. }
  1204. /**
  1205. *得到当前选择的下拉的选择索引
  1206. *
  1207. */
  1208. function getSelectedIndex()
  1209. {
  1210. return iSelectedIndex;
  1211. }
  1212. /**
  1213. *设置当前的选择项
  1214. *
  1215. */
  1216. function setSelectedIndex(index)
  1217. {
  1218. if (isTableRow(index) == false)
  1219. {
  1220. return;
  1221. }
  1222. setSelectedItem(oListTableE.rows[index].cells[0]);
  1223. }
  1224. /**
  1225. *根据人机工程规范计算下拉框的显示高度
  1226. *
  1227. */
  1228. function calcHeight()
  1229. {
  1230. //通过dropHeight属性强行设置下拉框的高度
  1231. if (eval(useDropHeight) == false)
  1232. {
  1233. if (getCount() >= 7)
  1234. {
  1235. return (parseInt(cellHeight) + 1) * 7 + 3;
  1236. }
  1237. else
  1238. {
  1239. return (getCount() * (parseInt(cellHeight) + 1) + 3);
  1240. }
  1241. }
  1242. else
  1243. {
  1244. return parseInt(dropHeight);
  1245. }
  1246. }
  1247. /**
  1248. *设置弹出的下拉列表的属性
  1249. *
  1250. */
  1251. function setPop(popBody)
  1252. {
  1253. popBody.style.borderStyle = "solid";
  1254. popBody.style.borderWidth = "1px";
  1255. popBody.style.borderColor = focusBorderColor;
  1256. popBody.style.overflowX = "hidden";
  1257. popBody.style.overflowY = "auto";
  1258. popBody.style.scrollbarFaceColor = "#e3e3d1";
  1259. popBody.style.fontSize = "9pt";
  1260. popBody.style.scrollbarShadowColor = "#d5d2c4";
  1261. popBody.style.scrollbarArrowColor = "0f59dd";
  1262. popBody.style.scrollbarTrackColor = "#d5d2c4";;
  1263. //popBody.style.backgroundColor = "#ecece8";
  1264. }
  1265. /**
  1266. *弹出的下拉列表中的mouseover,mouseout,mousedown事件处理
  1267. *
  1268. */
  1269. function popEvent(pop)
  1270. {
  1271. var popTable = getPopTable(pop);
  1272. if (popTable == null)
  1273. {
  1274. return;
  1275. }
  1276. for (var i = 0; i < popTable.rows.length; i ++)
  1277. {
  1278. popTable.rows[i].cells[0].onmousedown = popMouseDown;
  1279. popTable.rows[i].cells[0].onmouseover = popMouseOver;
  1280. popTable.rows[i].cells[0].onmouseout = popMouseOut;
  1281. }
  1282. }
  1283. /**
  1284. *弹出的下拉框中的mousedown事件
  1285. *
  1286. */
  1287. function popMouseDown()
  1288. {
  1289. var iOldIndex = iSelectedIndex;
  1290. iSelectedIndex = this.parentElement.rowIndex;
  1291. oInputE.itemid = this.itemid;
  1292. oInputE.desc = this.desc;
  1293. oInputE.data = this.data;
  1294. oHiddenE.value = this.itemid;
  1295. oInputE.valueChanged = true;
  1296. oInputE.value = this.desc;
  1297. value = this.desc;
  1298. popWin.hide();
  1299. if (iOldIndex != iSelectedIndex)
  1300. {
  1301. evtIndexChange.fire();
  1302. evtChange.fire();
  1303. }
  1304. }
  1305. /**
  1306. *弹出的下拉框中的mouseover事件
  1307. *
  1308. */
  1309. function popMouseOver()
  1310. {
  1311. //修改已经选择项的数据
  1312. if (iSelectedIndex != -1)
  1313. {
  1314. updateStyle(this.parentElement.parentElement.rows[iSelectedIndex].cells[0],initializeBGColor,initializeTextFontColor);
  1315. }
  1316. updateStyle(this,focusBGColor,focusTextFontColor);
  1317. }
  1318. /**
  1319. *弹出的下拉框中的mouseout事件
  1320. *
  1321. */
  1322. function popMouseOut()
  1323. {
  1324. updateStyle(this,initializeBGColor,initializeTextFontColor);
  1325. }
  1326. /**
  1327. *把下拉列表中选中的item设置到input输入框中,isKeyUp表示是按键按下了
  1328. *
  1329. */
  1330. function setSelectedItem(cell,isKeyUp)
  1331. {
  1332. if (cell == null || !cell.tagName)
  1333. {
  1334. return;
  1335. }
  1336. if (cell.tagName != "TD")
  1337. {
  1338. return;
  1339. }
  1340. iSelectedIndex = cell.parentElement.rowIndex;
  1341. oInputE.itemid = cell.itemid;
  1342. oInputE.desc = cell.desc;
  1343. oInputE.data = cell.data;
  1344. oHiddenE.value = cell.itemid;
  1345. //如果按键按下,则不能设置oInputE.value的值,否则造成循环
  1346. if (isKeyUp == true)
  1347. {
  1348. oInputE.valueChanged = true;
  1349. }
  1350. else
  1351. {
  1352. oInputE.value = cell.desc;
  1353. }
  1354. value = cell.desc;
  1355. }
  1356. /**
  1357. *得到光标的位置
  1358. *
  1359. */
  1360. function getCursorPosition()
  1361. {
  1362. var oSrc = event.srcElement;
  1363. var textRange = element.document.selection.createRange();
  1364. textRange.collapse(false);
  1365. textRange.setEndPoint("StartToStart", oInputE.createTextRange());
  1366. return textRange.text.length;
  1367. }
  1368. /**
  1369. *移动光标到指定位置
  1370. *
  1371. */
  1372. function moveCursor(oInput,iPos)
  1373. {
  1374. if (iPos > oInput.value.length)
  1375. {
  1376. return;
  1377. }
  1378. var textRange = oInput.createTextRange();
  1379. textRange.moveStart('character',iPos);
  1380. textRange.collapse(true);
  1381. textRange.select();
  1382. }
  1383. /**
  1384. *修改显示风格
  1385. */
  1386. function updateStyle(cell,bgcolor,forecolor)
  1387. {
  1388. cell.style.backgroundColor = bgcolor;
  1389. cell.style.color = forecolor;
  1390. }
  1391. /**
  1392. *得到弹出的下拉框中的Table对象
  1393. *
  1394. */
  1395. function getPopTable(pop)
  1396. {
  1397. for (var i = 0 ; i < pop.document.all.length; i ++)
  1398. {
  1399. if (pop.document.all[i].tagName == "TABLE")
  1400. {
  1401. return pop.document.all[i];
  1402. }
  1403. }
  1404. return null;
  1405. }
  1406. /**
  1407. *使用xml格式加载数据项
  1408. *
  1409. */
  1410. function loadXML(sData,isClear)
  1411. {
  1412. if (!sData)
  1413. {
  1414. return;
  1415. }
  1416. var xmlDOM = null;
  1417. var xmlData = null;
  1418. try
  1419. {
  1420. var xmlDOM = new ActiveXObject("Microsoft.XMLDOM");
  1421. xmlDOM.loadXML(sData);
  1422. var xmlData = xmlDOM.documentElement;
  1423. }
  1424. catch(e)
  1425. {
  1426. return;
  1427. }
  1428. if (xmlData == null)
  1429. {
  1430. return;
  1431. }
  1432. if (isClear == true)
  1433. {
  1434. clearItems();
  1435. }
  1436. for (var i = 0; i < xmlData.childNodes.length; i ++)
  1437. {
  1438. addItem(getProperty(xmlData.childNodes[i],"itemid"),
  1439. getProperty(xmlData.childNodes[i],"desc"),
  1440. getProperty(xmlData.childNodes[i],"data"),
  1441. getProperty(xmlData.childNodes[i],"selected")
  1442. );
  1443. }
  1444. }
  1445. /**
  1446. * 得到xml项中的属性(node为节点,name为属性名称)
  1447. *
  1448. */
  1449. function getProperty(node,propname)
  1450. {
  1451. var propList = node.attributes;
  1452. var propLength = propList.length;
  1453. if (propLength == 0)
  1454. {
  1455. return null;
  1456. }
  1457. for (var i = 0; i < propLength; i ++)
  1458. {
  1459. if(propList.item(i).name == propname)
  1460. {
  1461. return propList.item(i).value;
  1462. }
  1463. }
  1464. return null;
  1465. }
  1466. /**
  1467. *根据index得到itemid
  1468. *
  1469. */
  1470. function getItemID(index)
  1471. {
  1472. if (!isTableRow(index))
  1473. {
  1474. return;
  1475. }
  1476. return (oListTableE.rows[index].cells[0].itemid);
  1477. }
  1478. /**
  1479. *根据index,设置id
  1480. *
  1481. */
  1482. function setItemID(index,itemid)
  1483. {
  1484. if (!isTableRow(index))
  1485. {
  1486. return;
  1487. }
  1488. oListTableE.rows[index].cells[0].itemid = itemid;
  1489. if (index == iSelectedIndex)
  1490. {
  1491. setSelectedItem(oListTableE.rows[index].cells[0]);
  1492. }
  1493. }
  1494. /**
  1495. *根据index得到desc
  1496. *
  1497. */
  1498. function getItemDesc(index)
  1499. {
  1500. if (!isTableRow(index))
  1501. {
  1502. return;
  1503. }
  1504. return (oListTableE.rows[index].cells[0].desc);
  1505. }
  1506. /**
  1507. *根据index设置desc
  1508. *
  1509. */
  1510. function setItemDesc(index,desc)
  1511. {
  1512. if (!isTableRow(index))
  1513. {
  1514. return;
  1515. }
  1516. oListTableE.rows[index].cells[0].desc = desc;
  1517. if (index == iSelectedIndex)
  1518. {
  1519. setSelectedItem(oListTableE.rows[index].cells[0]);
  1520. }
  1521. }
  1522. /**
  1523. *根据index得到data
  1524. *
  1525. */
  1526. function getItemData(index)
  1527. {
  1528. if (!isTableRow(index))
  1529. {
  1530. return;
  1531. }
  1532. return (oListTableE.rows[index].cells[0].data);
  1533. }
  1534. /**
  1535. *根据index设置data
  1536. *
  1537. */
  1538. function setItemData(index,data)
  1539. {
  1540. if (!isTableRow(index))
  1541. {
  1542. return;
  1543. }
  1544. oListTableE.rows[index].cells[0].data = data;
  1545. if (index == iSelectedIndex)
  1546. {
  1547. setSelectedItem(oListTableE.rows[index].cells[0]);
  1548. }
  1549. }
  1550. /**
  1551. *根据id值找到index值(只找第一项符合条件的)
  1552. *
  1553. */
  1554. function getIndexByID(itemid)
  1555. {
  1556. //返回-1表示没有找到
  1557. if (itemid == null)
  1558. {
  1559. return -1;
  1560. }
  1561. for (var i = 0; i < getCount(); i ++)
  1562. {
  1563. if (oListTableE.rows[i].cells[0].itemid == itemid)
  1564. {
  1565. return oListTableE.rows[i].rowIndex;
  1566. }
  1567. }
  1568. return -1;
  1569. }
  1570. /**
  1571. *根据desc的值找到index值(只找第一个符合条件的)
  1572. *
  1573. */
  1574. function getIndexByDesc(desc)
  1575. {
  1576. //返回-1表示没有找到
  1577. if (desc == null)
  1578. {
  1579. return -1;
  1580. }
  1581. for (var i = 0; i < getCount(); i ++)
  1582. {
  1583. if (oListTableE.rows[i].cells[0].desc == desc)
  1584. {
  1585. return oListTableE.rows[i].rowIndex;
  1586. }
  1587. }
  1588. return -1;
  1589. }
  1590. /**
  1591. *根据index更新数据项的值
  1592. *
  1593. */
  1594. function updateItem(index,itemid,desc,data,selected)
  1595. {
  1596. if (!isTableRow(index))
  1597. {
  1598. return;
  1599. }
  1600. oListTableE.rows[index].cells[0].itemid = itemid;
  1601. oListTableE.rows[index].cells[0].desc = desc;
  1602. oListTableE.rows[index].cells[0].data = data;
  1603. oListTableE.rows[index].cells[0].selected = selected;
  1604. if (index == iSelectedIndex)
  1605. {
  1606. setSelectedItem(oListTableE.rows[index].cells[0]);
  1607. }
  1608. }
  1609. /**
  1610. *设置 css相关的属性
  1611. *
  1612. */
  1613. function initCss()
  1614. {
  1615. if (element.currentStyle.textbox_btn_1 != null)
  1616. {
  1617. sImageInit = cssPath + element.currentStyle.textbox_btn_1;
  1618. }
  1619. else
  1620. {
  1621. sImageInit = imagePath + "textbox_btn_1.gif";
  1622. }
  1623. if (element.currentStyle.textbox_btnforbit != null)
  1624. {
  1625. sImageForbit = cssPath + element.currentStyle.textbox_btnforbit;
  1626. }
  1627. else
  1628. {
  1629. sImageForbit = imagePath + "textbox_btnforbit.gif";
  1630. }
  1631. if (element.currentStyle.textbox_btn_2 != null)
  1632. {
  1633. sImageDrop = cssPath + element.currentStyle.textbox_btn_2;
  1634. }
  1635. else
  1636. {
  1637. sImageDrop = imagePath + "textbox_btn_2.gif";
  1638. }
  1639. }
  1640. </script>
  1641. </public:component>