Home  >  Article  >  Web Front-end  >  JavaScript method to dynamically delete list box values_javascript skills

JavaScript method to dynamically delete list box values_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:45:291289browse

The example in this article describes the method of dynamically deleting list box values ​​​​in JavaScript. Share it with everyone for your reference. The details are as follows:

Use JavaScript to dynamically delete the values ​​in the list box. In actual application, the effect may be more complicated. This is just a basic functional unit, and many are expanded on this basis. Run the code and click "Delete" to delete the list. Delete the values ​​in the box one by one, leaving only one piece of data.

The screenshot of the running effect is as follows:

The specific code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>删除选项</title>
<style>
<!--
form{padding:0px; margin:0px; font:14px Arial;}
p{margin:0px; padding:3px;}
input{margin:0px; border:1px solid #000000;}
-->
</style>
<script language="javascript">
function RemoveOption(Box,iNum){
 var oForm = document.forms["myForm1"];
 var oBox = oForm.elements[Box];
 oBox.options[iNum] = null; 
}
</script>
</head>
<body>
<form method="post" name="myForm1">
球类:
<p>
<select id="ball" name="ball" multiple="multiple">
 <option value="Football">足球</option>
 <option value="Basketball">篮球</option>
 <option value="Volleyball">排球</option>
</select>
</p>
<input type="button" value="删除" onclick="RemoveOption('ball',1);" />
</form>
</body>
</html>

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn