现在的位置: 首页 > 综合 > 正文

selectbox学习笔记

2017年10月19日 ⁄ 综合 ⁄ 共 1831字 ⁄ 字号 评论关闭
 

<html>
    
<head>
        
<title>limited textarea</title>
        
<script type="text/javascript">
        
var TextUtil = new Object();
        TextUtil.isNotMax
=function(oTextArea)
        
{
            
return oTextArea.value.length !=oTextArea.getAttribute("maxlength");
        }

        
//禁止粘贴  onpaste="return false"

        
//select box,HTML DOM为每个<select/>元素定义了options集合,她是控件的所有的
        //<option/>元素的列表,要获取,option的显示的文本与值
        function testSelect()
        
{
            
var test = document.getElementById("testSelect");
            alert(test.options[
0].value);
            alert(test.options[
0].getAttribute("value"));
            alert(test.options[
0].firstChild.nodeValue);
            alert(test.options[
0].text);
            alert(test.options[
0].index);
            alert(test.options[
0].selected);
            test.options[
0].firstChild.nodeValue ="zhang xiong";
        }

        
//添加 一个option选项.
        function appendOption()
        
{
            
var test = document.getElementById("testSelect");
            
var appOption = document.createElement("option");
            appOption.setAttribute(
"value","4");
            appOption.appendChild(document.createTextNode(
"tina shi"));
            test.appendChild(appOption);
        }


        
//删除一个选项
        function deleteOption()
        
{
            
var test = document.getElementById("testSelect");
            test.options[
0]=null;
            test.remove(
0);
            
//两种删除选项的方式
        }

        
</script>
    
</head>
    
<body onload="deleteOption()">
      
<textarea rows="10" cols="120" maxlength="50" onkeypress="return TextUtil.isNotMax(this)">
      
</textarea>

      
<select id="testSelect">
            
<option value="1">fangzhiyong</option>
            
<option value="2">wanglei</option>
            
<option value="3">kong kai ping</option>
      
</select>
    
</body>
</html>
【上篇】
【下篇】

抱歉!评论已关闭.