게시판 본문 ASP, ASP.NET, IIS & Script - Read Only
| DHTML behavior 와 HTC 를 이용한 SELECT 의 확장 |
|---|
|
작성자: 박노철
작성일시: 2005-07-29 09:58,
조회수: 3,822
|
|
HTC 강좌를 보고 SELECT tag 에 각종 finder method 를 붙이는 HTC 를 만들어봤습
니다. 프로젝트 하다보면 SELECT tag 에서 text로 value 를 찾거나 value로 text를 찾 거나 index 를 찾거나 하는 등등의 일이 은근히 많이 필요한데요, 그럴때 유용하게 써먹을 수 있을 듯 합니다. 사용법은 다음과 같습니다.
<SELECT style="behavior:url(selectfinder.htc)" id="selFinderTest">
selFinderTest.findTextByValue("testText");
selFinderTest.findValueByText("testValue");
소스를 보시면 각종 함수가 있으니 자유롭게 확장해서 사용하세요~
<PUBLIC:COMPONENT>
<PUBLIC:METHOD NAME="findIndexByValue" />
<PUBLIC:METHOD NAME="findIndexByText" />
<PUBLIC:METHOD NAME="findValueByText" />
<PUBLIC:METHOD NAME="findTextByValue" />
<PUBLIC:METHOD NAME="selectIndexByText" />
<PUBLIC:METHOD NAME="selectIndexByValue" />
<PUBLIC:METHOD NAME="getConcatValues" />
<PUBLIC:METHOD NAME="getConcatText" />
<PUBLIC:METHOD NAME="getTextValuePair" />
<SCRIPT language="javascript">
function findIndexByValue(val) {
for(var i = 0; i < element.length; i++) {
if(element.options(i).value == val) return i;
}
return -1;
}
function findIndexByText(text) {
for(var i = 0; i < element.length; i++) {
if(element.options(i).text == text) return i;
}
return -1;
}
function findValueByText(txt) {
try {
return element.options(this.findIndexByText(txt)).text;
} catch(e) {
return null;
}
}
function findTextByValue(val) {
try {
return element.options(this.findIndexByValue(val)).value;
} catch(e) {
return null;
}
}
function selectIndexByValue(val) {
element.selectedIndex = this.findIndexByValue(val);
}
function selectIndexByText(txt) {
element.selectedIndex = this.findIndexByText(txt);
}
function getConcatValues(delim) {
var result = "";
if(delim == null || delim == "") delim = ","
for(var i = 0; i < element.length; i++) {
result = result + element.options(i).value + delim;
}
// 끝에 붙은 delim 을 잘라냄
return result.substring(0, result.lastIndexOf(delim));
}
function getConcatText(delim) {
var result = "";
if(delim == null || delim == "") delim = ","
for(var i = 0; i < element.length; i++) {
result = result + element.options(i).text + delim;
}
// 끝에 붙은 delim 을 잘라냄
return result.substring(0, result.lastIndexOf(delim));
}
function getTextValuePair(delim) {
var result = "";
if(delim == null || delim == "") delim = ",";
for(var i = 0; i < element.length; i++) {
result = result
+ element.options(i).text
+ "="
+ element.options(i).value
+ delim;
}
return result.substring(0,result.lastIndexOf(delim));
}
</SCRIPT>
</PUBLIC:COMPONENT>
|
|
IP 주소: 165.141.120.133
|
전체 2 건의 댓글이 존재합니다.
|
송원석 |
정말 대단히 감사합니다. 매우 유용하게 참고하도록 하겠습니다. 감사합니다.
|
2005-07-29 10:17 |
|
송원석 |
그리고 코드는 원본을 훼손하지 않는 범위내에서 가독성을 높이기 위해 제가 나름대로 정리를 조금 하였습니다. 너그러이 양해해주시면 감사드리겠습니다. ^_^
|
2005-07-29 10:19 |
전체 2,095 건의 게시물,
84 페이지로 구성된
ASP, ASP.NET, IIS & Script 게시판의
36 페이지입니다.
|
게시물 | |||
|---|---|---|---|---|
| 1,257 |
영이 |
2005-08-04 | 1,089 | |
| 1,256 | 2005-08-04 | 3,491 | ||
| 1,255 |
영이 |
2005-08-04 | 1,086 | |
| 1,254 | 2005-08-04 | 3,539 | ||
| 1,253 |
영이 |
2005-08-04 | 1,033 | |
| 1,252 | 2005-08-04 | 3,554 | ||
| 1,251 |
영이 |
2005-08-08 | 1,148 | |
| 1,250 | 2005-08-09 | 3,511 | ||
| 1,249 |
궁금이 |
2005-08-03 | 1,027 | |
| 1,248 | 2005-08-03 | 3,378 | ||
| 1,247 | 2005-07-29 | 6,868 | ||
| 2005-07-29 | 3,822 | |||
| 1,245 | 2005-07-28 | 3,636 | ||
| 1,244 | 2005-07-28 | 3,360 | ||
| 1,243 | 2005-07-27 | 3,497 | ||
| 1,242 | 2005-07-27 | 3,754 | ||
| 1,241 | 2005-07-25 | 3,845 | ||
| 1,240 | 2005-07-26 | 3,818 | ||
| 1,239 |
쿠키에 대한 질문입니다. [2] |
omar |
2005-07-21 | 1,015 |
| 1,238 |
iE 아날라이즈에서요... [1] |
2005-07-21 | 3,596 | |
| 1,237 |
강문성 |
2005-07-20 | 1,194 | |
| 1,236 | 2005-07-21 | 4,357 | ||
| 1,235 | 2005-07-27 | 3,631 | ||
| 1,234 | 2005-07-27 | 3,681 | ||
| 1,233 | 2005-07-20 | 3,703 |

sign in
join
re: EgoCube IE Analysis의 MSHTML 참조에 관하여...