반응형
// Standard javascript function to clear all the options in an HTML select element
// In this method, you provide the id of the select dropdown box
function ClearOptions(id)
{
document.getElementById(id).options.length = 0;
}
// Standard javascript function to clear all the options in an HTML select element
// In this method, you just provide the form name and dropdown box name
function ClearOptionsAlt(FormName, SelectName)
{
document.forms[FormName].elements[SelectName].options.length = 0;
}
// Fast javascript function to clear all the options in an HTML select element
// Provide the id of the select element
// References to the old <select> object will become invalidated!
// This function returns a reference to the new select object.
function ClearOptionsFast(id)
{
var selectObj = document.getElementById(id);
var selectParentNode = selectObj.parentNode;
var newSelectObj = selectObj.cloneNode(false); // Make a shallow copy
selectParentNode.replaceChild(newSelectObj, selectObj);
return newSelectObj;
}
// This is an alternative, simpler method. Thanks to Victor T.
// It does not appear to be as fast as the ClearOptionsFast method in FF 3.6.
function ClearOptionsFastAlt(id)
{
document.getElementById(id).innerHTML = "";
}
반응형
'PROGRAMING > JAVASCRIPT' 카테고리의 다른 글
[JavaScript] JavaScript Modules (49) | 2024.04.17 |
---|---|
[JAVASCRIPT] GET 파라미터 값 취득 (0) | 2011.07.23 |
[JAVASCRIPT] Url Encode/Decode 값 확인 (0) | 2011.06.10 |
[JAVASCRIPT] Event keyCode를 통한 입력체크 (0) | 2011.06.01 |