⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 动态生成.htm

📁 这是一些关于JavaScript的学习资料 希望对大家有用
💻 HTM
字号:
<html>
<head>
<title>Listing 28.11. Adding and Deleting List Options - 品络科技 pinluo.com</TITLE>

<script language="JavaScript" type="text/javascript" src="sniffer.js">
</script>

<script language="JavaScript" type="text/javascript">
<!--

// Create the new two-dimensional array
var state_array = new Array(63)

// Populate the array with two values in each element
populate_state_array()

// This function assigns values to the 
// two-dimensional object's properties
function State(name, code) {
    this.name = name
    this.code = code
}

// This function inserts two values into each array element
function populate_state_array() {
    state_array[0] = new State("Alabama", "AL")
    state_array[1] = new State("Alaska", "AK")
    state_array[2] = new State("Arizona", "AZ")
    state_array[3] = new State("Arkansas", "AR")
    state_array[4] = new State("California", "CA")
    state_array[5] = new State("Colorado", "CO")
    state_array[6] = new State("Connecticut", "CT")
    state_array[7] = new State("Delaware", "DE")
    state_array[8] = new State("District of Columbia", "DC")
    state_array[9] = new State("Florida", "FL")
    state_array[10] = new State("Georgia", "GA")
    state_array[11] = new State("Hawaii", "HI")
    state_array[12] = new State("Idaho", "ID")
    state_array[13] = new State("Illinois", "IL")
    state_array[14] = new State("Indiana", "IN")
    state_array[15] = new State("Iowa", "IA")
    state_array[16] = new State("Kansas", "KS")
    state_array[17] = new State("Kentucky", "KY")
    state_array[18] = new State("Louisiana", "LA")
    state_array[19] = new State("Maine", "ME")
    state_array[20] = new State("Maryland", "MD")
    state_array[21] = new State("Massachusetts", "MA")
    state_array[22] = new State("Michigan", "MI")
    state_array[23] = new State("Minnesota", "MN")
    state_array[24] = new State("Mississippi", "MS")
    state_array[25] = new State("Missouri", "MO")
    state_array[26] = new State("Montana", "MT")
    state_array[27] = new State("Nebraska", "NE")
    state_array[28] = new State("Nevada", "NV")
    state_array[29] = new State("New Hampshire", "NH")
    state_array[30] = new State("New Jersey", "NJ")
    state_array[31] = new State("New Mexico", "NM")
    state_array[32] = new State("New York", "NY")
    state_array[33] = new State("North Carolina", "NC")
    state_array[34] = new State("North Dakota", "ND")
    state_array[35] = new State("Ohio", "OH")
    state_array[36] = new State("Oklahoma", "OK")
    state_array[37] = new State("Oregon", "OR")
    state_array[38] = new State("Pennsylvania", "PA")
    state_array[39] = new State("Puerto Rico", "PR")
    state_array[40] = new State("Rhode Island", "RI")
    state_array[41] = new State("South Carolina", "SC")
    state_array[42] = new State("South Dakota", "SD")
    state_array[43] = new State("Tennessee", "TN")
    state_array[44] = new State("Texas", "TX")
    state_array[45] = new State("Utah", "UT")
    state_array[46] = new State("Vermont", "VT")
    state_array[47] = new State("Virginia", "VA")
    state_array[48] = new State("Washington", "WA")
    state_array[49] = new State("West Virginia", "WV")
    state_array[50] = new State("Wisconsin", "WI")
    state_array[51] = new State("Wyoming", "WY")
    state_array[52] = new State("Alberta", "AB")
    state_array[53] = new State("British Columbia", "BC")
    state_array[54] = new State("Manitoba", "MB")
    state_array[55] = new State("New Brunswick", "NB")
    state_array[56] = new State("Newfoundland", "NF")
    state_array[57] = new State("Northwest Territories", "NT")
    state_array[58] = new State("Nova Scotia", "NS")
    state_array[59] = new State("Ontario", "ON")
    state_array[60] = new State("Prince Edward Island", "PE")
    state_array[61] = new State("Quebec", "QC")
    state_array[62] = new State("Saskatchewan", "SK")
}

function populate_list(current_list) {

    // Reset the list
    current_list.length = 0
    
    // Run through the array of states
    for (counter = 0; counter < state_array.length; counter++) {
    
        // Add the state code as the value
        // and the state name as the text
        current_list.options[counter] = new Option(state_array[counter].name, state_array[counter].code)
    }
   
    // Netscape 4 needs to refresh the page
    if (its_ns4) {
        history.go(0)
    }
    
    // Select the first item
    current_list.options[0].selected = true
}

function display_code(current_list) {

    // Make sure the list is populated
    if (current_list.length > 0) {
    
        // Delete the selected option
        alert(current_list.options[current_list.selectedIndex].value)
    }
}

function delete_selected(current_list) {

    // Make sure the list is populated
    if (current_list.length > 0) {

        // Delete the selected option
        current_list.options[current_list.selectedIndex] = null

    }
}

//-->
</script>

</head>

<body>

<form>
<select name="state_list">
</select>

<p>
<input type="button"
       value="Populate State List"
       onClick="populate_list(this.form.state_list)">
<p>
<input type="button"
       value="Display State Code"
       onClick="display_code(this.form.state_list)">
<p>
<input type="button"
       value="Delete Selected Option"
       onClick="delete_selected(this.form.state_list)">

</form>

</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -