日期:2014-05-16  浏览次数:20318 次

上传图片功能如何实现?
有两个name均为"error"的input标签如下:
HTML code
<input type="radio" name="error"  value="yes" checked="checked"/>有
           <input type="radio" name="error"  value="no" />无 

若选择“有”,则出现允许用户上传图片的按钮,该如何实现?

------解决方案--------------------
HTML code

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="gb2312" />
        <title></title>    
        <style>
            body {font-size:12px;}
        </style>        
    </head>
    <body>
        <input type="radio" name="error"  value="yes" checked="checked"/>有
        <input type="radio" name="error"  value="no" />无
        <br />
        <button id="up">上传</button>
        <script>
            function $(el){
                return typeof el == 'string' ? document.getElementById(el) : el;
            }
            function $n(name, cot){
                cot = cot || document;
                return cot.getElementsByName(name);
            }
            var btn = $n('error');
            btn[0].onclick = function(){
                $('up').style.display = 'block';
            }
            btn[1].onclick = function(){
                $('up').style.display = 'none';
            }            
        </script>
    </body>
</html>