ÁöÁ¤µÈ °Ôü¿¡ Ç¥Çö½ÄÀ» ¼³Á¤ÇÑ´Ù.
ÇʼöÀûÀÎ ¿ä¼ÒÀ̸ç, Ç¥Çö½Ä sExpressionÀÌ Ãß°¡µÉ ¼Ó¼ºÀÇ À̸§À» ÁöÁ¤ÇÏ´Â ¹®ÀÚ¿ÀÌ´Ù.
ÇʼöÀûÀÎ ¿ä¼ÒÀ̸ç, ¼¼¹ÌÄÝ·Ð(;)À̳ª µû¿ÈÇ¥(',") ¾øÀÌ À¯È¿ÇÑ ½ºÅ©¸³Æ®(Script, JavaScript, VBSCript) ¹®ÀåÀ¸·Î ÀÛ¼ºÇÑ Ç¥Çö½ÄÀÌ´Ù. ÀÌ ¹®ÀÚ¿Àº ÇöÀç ÆäÀÌÁöÀÇ ´Ù¸¥ ¼Ó¼ºµéÀÇ ÂüÁ¶¸¦ Æ÷ÇÔÇÒ ¼ö ÀÖ´Ù. ½ºÅ©¸³Æ® ¼Ó¿¡ Æ÷ÇÔµÈ °³Ã¼ÀÇ ¼Ó¼ºµé¿¡´Â ¹è¿º¯¼ö ÂüÁ¶¸¦ Çã¿ëÇÏÁö ¾Ê´Â´Ù.
JScript | µðÆúÆ®À̸ç, JScript ¾ð¾îÀÌ´Ù. |
VBScript | VBScript ¾ð¾îÀÌ´Ù. |
JavaScript | JavaScript ¾ð¾îÀÌ´Ù. |
¹Ýȯ°ªÀº ¾ø´Ù.
setExpression ¸Þ¼µå´Â Áö¿øµÇ´Â CSS ¼Ó¼ºµé(Cascading Style Sheets)°úÀбâ/¾²±â DHTML ¼Ó¼ºµé¿¡ Ç¥Çö½ÄÀ» ¼³Á¤Çϴµ¥ »ç¿ëµÈ´Ù.
setExpression ¸Þ¼µå¿¡ ÀÇÇÏ¿© ¼³Á¤µÈ Ç¥Çö½ÄÀ» Á¦°ÅÇϱâ À§ÇÏ¿©, removeExpression ¸Þ¼µå¸¦ »ç¿ëÇÑ´Ù.
´ÙÀ½ ¹®¹ýÀº CSS ¼Ó¼ºµé(Cascading Style Sheets)°ú DHTML ¼Ó¼ºµé¿¡¼ Ç¥Çö½ÄÀ» Á¦°ÅÇÏ´Â ¹æ½ÄÀ» º¸¿©ÁØ´Ù.
object.setExpression(sPropName,sExpression,sLang)
object.style.setExpression(sPropName,sExpression,sLang)
<ELEMENT style="sAttributeName:expression(sExpression)">
sLang ÆĶó¸ÞÅÍ¿¡ ÀÇÇÏ¿© ÁöÁ¤µÈ ¾ð¾î·Î Ç¥ÇöµÈ µ¥ÀÌÅÍ Çü½ÄÀº Ç¥Çö½Ä sExpression¿¡ Çã¿ëµÈ ÇϳªÀÇ °¡´ÉÇÑ °ª¿¡ ¸Â¾Æ¾ß ÇÑ´Ù.
óÀ½ ÆĶó¸ÞÅÍ¿¡ ÀÇÇÏ¿© ÁöÁ¤¿Þ ¼Ó¼ºÀ̳ª ¾ÖÆ®¸®ºäÆ®°¡ ¹®ÀÚ¿À» ÇÊ¿ä·Î ÇÏ´Â °æ¿ì¿¡´Â, µÎ¹ø° ÆĶó¸ÞÅÍÀÇ µ¥ÀÌÅÍ Å¸ÀÔÀº ¹®ÀÚ¿©À̾î¾ß ÇÑ´Ù. ¾Æ´Ï¸é setExpression ¸Þ¼µå¸¦ ¼öÇàÇϱâ Àü¿¡ µÎ¹ø° ÆĶó¸ÞÅÍ°¡ ÆÇÁ¤µÇ°í, Ç¥Çö½ÄÀÌ ÆÇÁ¤ÀÇ °á°ú¿¡µû¶ó ¼³Á¤µÇµµ·Ï ÇÑ´Ù.
Ç¥Çö½Ä ¼Ó¿¡¼ °³Ã¼ÀÇ uniqueID ¼Ó¼ºÀ» »ç¿ëÇÏ´Â °ÍÀº °³Ã¼¸¦ ÂüÁ¶ÇÏ°Ô ÇÑ´Ù. Ç¥Çö½Ä¿¡¼ uniqueIDÀÇ »ç¿ëÀº °³Ã¼¸¦ ÂüÁ¶Çϴµ¥ »ç¿ëÇÏ´Â id ´ë½Å¿¡ ÇÏ¿© »ç¿ëÇÏ´Â ¹æ½ÄÀÌ´Ù.
cssText ¼Ó¼ºÀº ź·ÂÀû ¼Ó¼ºµéÀÌ ¬¿ëµÇÁö ¾Ê´Â ÇϳªÀÇ À¯ÀÏÇÑ ¼Ó¼ºÀÌ´Ù. cssText ¼Ó¼ºÀ» ź·ÂÀû ¼Ó¼º ¸Þ¼µåµé °°ÀÌ »ç¿ëÇÏÁö ¸»¾Æ¾ß ÇÑ´Ù.
´ÙÀ½Àº
object.style.setExpression('height','document.style.fontSize+13');
object.style.setExpression('width','document.body.style.fontSize');
°³Ã¼ | script | IE |
---|
setExpression ¸Þ¼µå¿Í removeExpression ¸Þ¼µå·Î div¹Ú½ºÀÇ width ¼Ó¼º Ç¥Çö½ÄÀ» ¼³Á¤ÇÏ°í, Á¦°ÅÇÏ´Â ¿¹Á¦ÀÌ´Ù.
box1Obj <INPUT type=text id=box1Obj value=50 size=3 onchange="showLength.innerText=box3Obj.style.width">+ box2Obj <INPUT type=text id=box2Obj value=50 size=3 onchange="showLength.innerText=box3Obj.style.width"> : box2Obj.style.width <SPAN id=showLength></SPAN><BR> <DIV id=box3Obj style="background-color:blue"></DIV><BR> <SCRIPT> var sExpress,bVal; document.onlad=setexp(); function setexp(){ box3Obj.style.setExpression('width','eval(box1Obj.value)+eval(box2Obj.value)','jscript'); showLength.innerText=box3Obj.style.width; } function getexp(){ sExpress=box3Obj.style.getExpression('width'); str='û»ö ¹Ú½ºÀÇ widthÀÇ Ç¥Çö½ÄÀº ' + sExpress + 'ÀÌ°í,<BR>'; str+='ÀÌ width ¼Ó¼ºÀº °ª ' + box3Obj.style.width+'À» °®´Â´Ù.'; showA.innerHTML=str; showLength.innerText=box3Obj.style.width; } function remexp(){ bVal=box3Obj.style.removeExpression('width'); showA.innerHTML='Ç¥Çö½ÄÀÌ Á¦°ÅµÇ¾ú³ª? '+bVal; } </SCRIPT> <INPUT type=button id=Button1 value="Ç¥Çö½Ä ³»¿ë" onclick="getexp()"> <INPUT type=button id=Button2 value="Ç¥¼Ç½Ä Á¦°Å" onclick="remexp()"> <INPUT type=button id=Button3 value="Ç¥Çö½Ä »ý¼º" onclick="setexp()"><BR> <DIV id=showA>°á°ú Ç¥½Ãâ</DIV>
Á¦Ç° | ¼ö·® | ´Ü°¡ | ÇÕ°è |
---|---|---|---|
¸Àµ¿»ê | 2 | 500 | |
¾Ë»çÅÁ | 5 | 800 | |
ÃÑ°è |
tableÀÇ innerText ¼Ó¼ºÀ» ¾÷µ¥ÀÌÆ®Çϱâ À§ÇÏ¿© uniqueID ¼Ó¼º°ú setExpression ¸Þ¼µå¸¦ »ç¿ëÇÏ¿´´Ù.
<SCRIPT> function doCalc(){ var iLen=oTable.rows.length-1; for(var i=1;i< iLen;i++){ var oRow=oTable.rows[i]; var oCells=oRow.cells; oCells(3).setExpression('innerText', 'doGetVal(' + oRow.uniqueID + ')'); } var oGrand=oTable.rows(iLen).cells(1); oGrand.setExpression('innerText','doLineTotal()'); } function doLineTotal(){ var iValue=0; var iLen=oTable.rows.length-1; for(var i=1;i< ilen;i++){ iValue+=parseFloat(oTable.rows(i).cells(3).innerText); } return iValue; } function doGetVal(oRow){ var oCells=oRow.cells; var oPrice=oCells(2); var oQuantity=oCells(1); var sPrice; var sQuantity; if (oPrice.childNodes[0].nodeName=='#text'){ sPrice=oPrice.innerText; } else{ var vPrice=oPrice.childNodes[0].value; sPrice=(vPrice=='' ? '0' : vPrice); } if (oQuantity.childNodes[0].nodeName=='#text'){ sQuantity=oQuantity.innerText; } else{ var vQuantity=oQuantity.childNodes[0].value; sQuantity=(vQuantity=='' ? '0' : vQuantity); } var vAlg1=parseFloat(sPrice) * parseFloat(sQuantity); return vAlg1; } </SCRIPT> <TABLE id="oTable" border=1 width=500 style="text-align:center"> <TR> <TH>Á¦Ç°</TH><TH>¼ö·®</TH> <TH>´Ü°¡</TH><TH>ÇÕ°è</TH> </TR> <TR> <TD>¸Àµ¿»ê</TD><TD EDIT="true">2</TD> <TD EDIT="true">500</TD><TD></TD> </TR> <TR> <TD>¾Ë»çÅÁ</TD><TD EDIT="true">5</TD> <TD EDIT="true">800</TD><TD></TD> </TR> <TR> <TH COLSPAN=3>ÃÑ°è</TH><TH></TH> </TR> </TABLE> <P><BUTTON onclick="doCalc()">°è»ê Àû¿ë</BUTTON></P>