123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607 |
- <!--/******************************************************************
- ** 文件名: KDTextField.htc
- ** Copyright (c) 2005 金蝶国际软件集团有限公司 研发中心
- ** http://www.kingdee.com
- **
- ** 创建人: 叶汉良
- ** 日 期: 2005.06.13
- **
- ** 描述:单行文本输入控件
- ** 版 本:Web V1.0
- ******************************************************************/-->
- <public:component tagName="KDTextField" lightWeight=true>
- <public:attach event="oncontentready" onevent="kdTextFieldReady()" />
- <public:attach event="onpropertychange" onevent="kdTextFieldPropertyChange()"/>
- <public:event name="onEvtClick" id = "evtClick">
- <public:event name="onEvtMouseDown" id = "evtMouseDown">
- <public:event name="onEvtMouseUp" id = "evtMouseUp">
- <public:event name="onEvtMouseOver" id = "evtMouseOver">
- <public:event name="onEvtMouseOut" id = "evtMouseOut">
- <public:event name="onEvtMouseMove" id = "evtMouseMove">
- <public:event name="onEvtFocus" id = "evtFocus">
- <public:event name="onEvtBlur" id = "evtBlur">
- <public:event name="onEvtKeyDown" id = "evtKeyDown">
- <public:event name="onEvtKeyUp" id = "evtKeyUp">
- <public:event name="onEvtKeyPress" id = "evtKeyPress">
- <public:event name="onEvtChange" id = "evtChange">
- <public:event name="onEvtBeforePaste" id = "evtBeforePaste">
- <public:property name="initializeBorderColor" value="#B4B4B4"/>
- <public:property name="initializeBGColor" value="#FFFFFF"/>
- <public:property name="initializeTextFontColor" value="#000000"/>
- <public:property name="focusBorderColor" value="#5C85B3"/>
- <public:property name="focusBGColor" value="#F9F9F9"/>
- <public:property name="focusTextFontColor" value="#000000"/>
- <public:property name="readonlyBorderColor" value="#B4B4B4"/>
- <public:property name="readonlyBGColor" value="#FFFFFF"/>
- <public:property name="readonlyTextFontColor" value="#777777"/>
- <public:property name="disableBorderColor" value="#B4B4B4"/>
- <public:property name="disableBGColor" value="#D9D9D0"/>
- <public:property name="disableTextFontColor" value="#777777"/>
- <public:property name="mustBorderColor" value="#B4B4B4"/>
- <public:property name="mustBGColor" value="#FCFBCE"/>
- <public:property name="mustTextFontColor" value="#000000"/>
- <public:property name="width" value="170"/>
- <public:property name="height" value="19"/>
- <public:property name="readonly" value="false"/>
- <public:property name="disable" value="false"/>
- <public:property name="name" value=""/>
- <public:property name="value" get="getValue" put="putValue"/>
- <public:property name="IDName" value=""/>
- <public:property name="IDValue" value=""/>
- <public:property name="maxLength" value=""/>
- <public:property name="fontSize1" value="9pt"/>
- <public:property name="fontFamily1" value="arial"/>
- <public:property name="dataType" value=""/>
- <public:property name="tabIndex1" value=""/>
- <public:property name="tips" value=""/>
- <public:property name="mustInput" value="false"/>
- <public:property name="mustInputMsg" value=""/>
- <public:property name="align" value="left"/>
- <public:property name="enter2tab" value="true"/>
- <public:method name="focus"/>
- </public:component>
- <script language="javascript">
- var sValue = "";
- /**
- *初始化处理的相关内容
- *
- */
- function kdTextFieldReady()
- {
- element.innerHTML = "<input type='text'/><input type='hidden'>";
- initCss();
-
- var oInputE = element.children(0);
- var oStyle = oInputE.style;
-
- oStyle.paddingLeft = 3;
- oStyle.width = width;
- oStyle.height = height;
- if (height >= 19)
- {
- oStyle.paddingTop = 2 + (parseInt(height) - 19) / 5;
- }
- else
- {
- oStyle.paddingTop = 0;
- }
-
- oStyle.borderStyle = "solid";
- oStyle.borderWidth = 1;
- oInputE.value = sValue;
- oStyle.fontFamily = fontFamily1;
- oStyle.fontSize = fontSize1;
- oInputE.name = name;
- oInputE.title = tips;
- oStyle.textAlign = align;
-
- if (maxLength != null && maxLength != "")
- {
- element.children(0).maxLength = maxLength;
- }
-
- //不可用状态
- if (eval(disable) == true)
- {
- oStyle.borderColor = disableBorderColor;
- oStyle.backgroundColor = disableBGColor;
- oStyle.color = disableTextFontColor;
- //此处不使用disabled这个属性,否则文字的颜色无法进行修改
- oInputE.readOnly = true;
- oInputE.tabIndex = "";
- }
- else
- {
- //只读状态
- if (eval(readonly) == true)
- {
- oStyle.borderColor = readonlyBorderColor;
- oStyle.backgroundColor = readonlyBGColor;
- oStyle.color = readonlyTextFontColor;
- oInputE.readOnly = true;
- }
- //必录项
- else if (eval(mustInput) == true)
- {
- oStyle.borderColor = mustBorderColor;
- oStyle.backgroundColor = mustBGColor;
- oStyle.color = mustTextFontColor;
- }
- else
- {
- oStyle.borderColor = initializeBorderColor;
- oStyle.backgroundColor = initializeBGColor;
- oStyle.color = initializeTextFontColor;
- }
- oInputE.tabIndex = tabIndex1;
- }
- element.children(1).name = IDName;
- element.children(1).value = IDValue;
-
- oInputE.attachEvent("onclick",function(){execute("click")});
- oInputE.attachEvent("onmousedown",function(){execute("mousedown")});
- oInputE.attachEvent("onmouseover",function(){execute("mouseover")});
- oInputE.attachEvent("onmouseout",function(){execute("mouseout")});
- oInputE.attachEvent("onmouseup",function(){execute("mouseup")});
- oInputE.attachEvent("onmousemove",function(){execute("mousemove")});
-
- oInputE.attachEvent("onfocus",function(){execute("focus")});
- oInputE.attachEvent("onblur",function(){execute("blur")});
-
- oInputE.attachEvent("onkeypress",function(){return execute("keypress");});
- oInputE.attachEvent("onkeydown",function(){execute("keydown")});
- oInputE.attachEvent("onkeyup",function(){execute("keyup")});
-
- oInputE.attachEvent("onchange",function(){execute("change")});
- oInputE.attachEvent("onbeforepaste",function(){return execute("beforepaste");});
- oInputE.attachEvent("onselectstart",function(){return execute("selectstart");});
- }
- /**
- *属性改变时相关的属性设置
- *
- */
- function kdTextFieldPropertyChange()
- {
- if (element.initcssing == true)
- {
- return;
- }
- var oStyle = element.children(0).style;
-
- switch(event.propertyName.toString().toLowerCase())
- {
- case "width":
- {
- oStyle.width = width;
- break;
- }
- case "height":
- {
- oStyle.height = height;
- break;
- }
-
- //初始化颜色发生了变化
- case "initializebordercolor":
- {
- if (eval(disable) != true && eval(readonly) != true && eval(mustInput) != true)
- {
- oStyle.borderColor = initializeBorderColor;
- }
- break;
- }
- case "initializebgcolor":
- {
- if (eval(disable) != true && eval(readonly) != true && eval(mustInput) != true)
- {
- oStyle.backgroundColor = initializeBGColor;
- }
- break;
- }
- case "initializetextfontcolor":
- {
- if (eval(disable) != true && eval(readonly) != true && eval(mustInput) != true)
- {
- oStyle.color = initializeTextFontColor;
- }
- break;
- }
-
- //只读颜色发生了变化
- case "readonlybordercolor":
- {
- if (eval(disable) != true && eval(readonly) == true)
- {
- oStyle.borderColor = readonlyBorderColor;
- }
- break;
- }
- case "readonlybgcolor":
- {
- if (eval(disable) != true && eval(readonly) == true)
- {
- oStyle.backgroundColor = readonlyBGColor;
- }
- break;
- }
- case "readonlytextfontcolor":
- {
- if (eval(disable) != true && eval(readonly) == true)
- {
- oStyle.color = readonlyTextFontColor;
- }
- break;
- }
-
- //disable的时候颜色发生了变化
- case "disablebordercolor":
- {
- if (eval(disable) == true)
- {
- oStyle.borderColor = disableBorderColor;
- }
- break;
- }
- case "disablebgcolor":
- {
- if (eval(disable) == true)
- {
- oStyle.backgroundColor = disableBGColor;
- }
- break;
- }
- case "disabletextfontcolor":
- {
- if (eval(disable) == true)
- {
- oStyle.color = disableTextFontColor;
- }
- break;
- }
-
- //只读发生了变化
- case "readonly":
- {
- if (eval(disable) != true)
- {
- //变化为只读状态
- if (eval(readonly) == true)
- {
- oStyle.borderColor = readonlyBorderColor;
- oStyle.backgroundColor = readonlyBGColor;
- oStyle.color = readonlyTextFontColor;
- element.children(0).readOnly = true;
- }
- else
- {
- if (eval(mustInput) == true)
- {
- oStyle.borderColor = initializeBorderColor;
- oStyle.backgroundColor = initializeBGColor;
- oStyle.color = initializeTextFontColor;
- }
- else
- {
- oStyle.borderColor = mustBorderColor;
- oStyle.backgroundColor = mustBGColor;
- oStyle.color = mustTextFontColor;
- }
- element.children(0).readOnly = false;
- }
- }
- break;
- }
-
- //不可使用发生了变化
- case "disable":
- {
- if (eval(disable) == true)
- {
- oStyle.borderColor = disableBorderColor;
- oStyle.backgroundColor = disableBGColor;
- oStyle.color = disableTextFontColor;
- element.children(0).readOnly = true;
- element.children(0).tabIndex = "";
- }
- else
- {
- if (eval(readonly) == true)
- {
- oStyle.borderColor = readonlyBorderColor;
- oStyle.backgroundColor = readonlyBGColor;
- oStyle.color = readonlyTextFontColor;
- element.children(0).readOnly = true;
- }
- else
- {
- if (eval(mustInput) == false)
- {
- oStyle.borderColor = initializeBorderColor;
- oStyle.backgroundColor = initializeBGColor;
- oStyle.color = initializeTextFontColor;
- }
- else
- {
- oStyle.borderColor = mustBorderColor;
- oStyle.backgroundColor = mustBGColor;
- oStyle.color = mustTextFontColor;
- }
- element.children(0).readOnly = false;
- }
-
- if (tabIndex1 != "")
- {
- element.children(0).tabIndex = tabIndex1;
- }
- }
- break;
- }
-
- case "fontsize1":
- {
- oStyle.fontSize = fontSize1;
- break;
- }
- case "tips":
- {
- element.children(0).title = tips;
- break;
- }
- default:
- break;
- }
- }
- /**
- *处理相关事件
- *
- */
- function execute(sEvent)
- {
- //不可处理状态下,不能进行处理
- if (eval(disable) == true)
- {
- return false;
- }
-
- var evt = window.document.createEventObject(event);
-
- if (sEvent == "click")
- {
- evtClick.fire(evt);
- }
- else if (sEvent == "mouseup")
- {
- evtMouseUp.fire(evt);
- }
- else if (sEvent == "mousedown")
- {
- element.isMouseDown = true;
- evtMouseDown.fire(evt);
- }
- else if (sEvent == "mousemove")
- {
- evtMouseMove.fire(evt);
- }
- else if (sEvent == "mouseover")
- {
- evtMouseOver.fire(evt);
- }
- else if (sEvent == "mouseout")
- {
- evtMouseOut.fire(evt);
- }
- else if (sEvent == "keyup")
- {
- evtKeyUp.fire(evt);
- }
- else if (sEvent == "keydown")
- {
- doKeyDown(evt);
- }
- else if (sEvent == "keypress")
- {
- evtKeyPress.fire(evt);
- }
- else if (sEvent == "change")
- {
- evtChange.fire(evt);
- }
- else if (sEvent == "beforepaste")
- {
- return doBeforePaste(evt);
- }
- else if (sEvent == "selectstart")
- {
- return doSelectStart(evt);
- }
-
- //可编辑状态下,可以修改边框的相关的颜色
- if (eval(readonly) != true)
- {
- if (sEvent == "focus")
- {
- doFocus(evt);
- }
- else if (sEvent == "blur")
- {
- if (eval(mustInput) == true)
- {
- element.children(0).style.borderColor = mustBorderColor;
- element.children(0).style.backgroundColor = mustBGColor;
- element.children(0).style.color = mustTextFontColor;
- if (element.children(0).value == "" && mustInputMsg != "")
- {
- alert(mustInputMsg);
- }
- }
- else
- {
- element.children(0).style.borderColor = initializeBorderColor;
- element.children(0).style.backgroundColor = initializeBGColor;
- element.children(0).style.color = initializeTextFontColor;
- }
- evtBlur.fire(evt);
- }
- }
- }
- /**
- *得到焦点
- *
- */
- function focus()
- {
- if (eval(disable) == true)
- {
- return;
- }
- element.children(0).focus();
- }
- /**
- *选择部分的时候修改显示的颜色
- *
- */
- function doSelectStart()
- {
- if (eval(disable) == true)
- {
- return false;
- }
- }
- /**
- *处理keyDown事件,主要按下enter键的时候,类似tab键按下
- *
- */
- function doKeyDown(evt)
- {
- if (event.keyCode == 13 && eval(enter2tab) == true)
- {
- evtKeyDown.fire(evt);
- event.keyCode = 9;
- return;
- }
- evtKeyDown.fire(evt);
- }
- /**
- *处理beforePaste事件,如果设置了maxlength的时候,不能随意粘贴
- *
- */
- function doBeforePaste(evt)
- {
- evtBeforePaste.fire(evt);
- return true;
- }
- /**
- *处理focus事件
- *
- */
- function doFocus(evt)
- {
- var oStyle = element.children(0).style;
- if (eval(mustInput) == false)
- {
- oStyle.borderColor = focusBorderColor;
- oStyle.backgroundColor = focusBGColor;
- oStyle.color = focusTextFontColor;
- }
- else
- {
- oStyle.borderColor = focusBorderColor;
- oStyle.backgroundColor = mustBGColor;
- oStyle.color = focusTextFontColor;
- }
-
- if (element.isMouseDown != true)
- {
- element.children(0).select();
- }
-
- element.isMouseDown = false;
- evtFocus.fire(evt);
- }
- /**
- *得到控件的值
- *
- */
- function getValue()
- {
- return element.children(0).value;
- }
- /**
- *设置控件的值
- *
- */
- function putValue(sValue1)
- {
- if (!element.children(0))
- {
- sValue = sValue1;
- }
- else
- {
- sValue = sValue1;
- element.children(0).value = sValue;
- }
- }
- /**
- *初始样式
- *
- */
- function initCss()
- {
- element.initcssing = true;
- var os = element.currentStyle;
- initializeBorderColor = getCssStyle(initializeBorderColor,"#B4B4B4",os.initializeBorderColor);
- initializeBGColor = getCssStyle(initializeBGColor,"#FFFFFF",os.initializeBGColor);
- initializeTextFontColor = getCssStyle(initializeTextFontColor,"#000000",os.initializeTextFontColor);
- focusBorderColor = getCssStyle(focusBorderColor,"#5C85B3",os.focusBorderColor);
- focusBGColor = getCssStyle(focusBGColor,"#F9F9F9",os.focusBGColor);
- focusTextFontColor = getCssStyle(focusTextFontColor,"#000000",os.focusTextFontColor);
- readonlyBorderColor = getCssStyle(readonlyBorderColor,"#B4B4B4",os.readonlyBorderColor);
- readonlyBGColor = getCssStyle(readonlyBGColor,"#FFFFFF",os.readonlyBGColor);
- readonlyTextFontColor = getCssStyle(readonlyTextFontColor,"#777777",os.readonlyTextFontColor);
- disableBorderColor = getCssStyle(disableBorderColor,"#B4B4B4",os.disableBorderColor);
- disableBGColor = getCssStyle(disableBGColor,"#D9D9D0",os.disableBGColor);
- disableTextFontColor = getCssStyle(disableTextFontColor,"#777777",os.disableTextFontColor);
- mustBorderColor = getCssStyle(mustBorderColor,"#B4B4B4",os.mustBorderColor);
- mustBGColor = getCssStyle(mustBGColor,"#FCFBCE",os.mustBGColor);
- mustTextFontColor = getCssStyle(mustTextFontColor,"#000000",os.mustTextFontColor);
- fontSize1 = getCssStyle(fontSize1,"9pt",os.fontSize1);
- fontFamily1 = getCssStyle(fontFamily1,"arial",os.fontFamily1);
-
- element.initcssing = false;
- }
- </script>
|