<input type="text" name="CompanyName" class="ipt-t ipt-t-dft" maxlength="100" />
<input type="file" name="upFile" id="upFile" onchange="Tools.previousSibling(this).value = this.value;" />
<div onclick="Tools.previousSibling(this).click();" class="btn btn-dft btn-dft-impt">
   <span>浏 览</span>
</div>
-----------
1:
因为input file的那个“浏览”按钮不美观
我要用div来代替
但是我这里没有办法执行他的onclick事件2:
"E:\Admin\CSS\Img\upload2.gif"
执行语句:Tools.previousSibling(this).value = this.value;" 
得到的却是:upload2.gif
要如何正确取值谢谢

解决方案 »

  1.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>test</title>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script type="text/javascript">
        window.onload=(function(){
            
        });
        </script>
    </head>
    <body>
    <input type="text" name="CompanyName" class="ipt-t ipt-t-dft" maxlength="100" /> 
    <input type="file" name="upFile" id="upFile" onchange="CompanyName.value = this.value;" /> 
    <div onclick="this.click=upFile.click();" class="btn btn-dft btn-dft-impt"> 
      <span>dddd</span> 
    </div> 
    </body>
    </html>
      

  2.   

    你把这个帖出来Tools.previousSibling(this)要不看不出来啊
      

  3.   

    var Tools = new Object();
    Tools.nextSibling = function(source, tagName) {
        var target = source.nextSibling;
        while (target) {
            if (target.nodeType == 1) {
                if (typeof (tagName) == "undefined") {
                    return target;
                }
                else if (target.tagName.toLowerCase() === tagName.toLowerCase()) {
                    return target;
                }
            }
            target = target.nextSibling;
        }
    }
    Tools.previousSibling = function(source, tagName) {
        var target = source.previousSibling;
        while (target) {
            if (target.nodeType == 1) {
                if (typeof (tagName) == "undefined") {
                    return target;
                }
                else if (target.tagName.toLowerCase() === tagName.toLowerCase()) {
                    return target;
                }
            }
            target = target.previousSibling;
        }
    }
      

  4.   

    可参考
    http://topic.csdn.net/u/20091222/00/2da91ff1-9bb2-431c-8ddf-bb3011d7efbe.html?946
    的方法
      

  5.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>test</title>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script type="text/javascript">
        window.onload=(function(){
            var Tools = new Object(); 
            Tools.nextSibling = function(source, tagName) { 
                var target = source.nextSibling; 
                while (target) { 
                    if (target.nodeType == 1) { 
                        if (typeof (tagName) == "undefined") { 
                            return target; 
                        } 
                        else if (target.tagName.toLowerCase() === tagName.toLowerCase()) { 
                            return target; 
                        } 
                    } 
                    target = target.nextSibling; 
                } 
            } 
            Tools.previousSibling = function(source, tagName) { 
                var target = source.previousSibling; 
                while (target) { 
                    if (target.nodeType == 1) { 
                        if (typeof (tagName) == "undefined") { 
                            return target; 
                        } 
                        else if (target.tagName.toLowerCase() === tagName.toLowerCase()) { 
                            return target; 
                        } 
                    } 
                    target = target.previousSibling; 
                } 
            }
            document.getElementById("upFile").onchange=function(){Tools.previousSibling(this).value = this.value;}
        });
        </script>
    </head>
    <body>
    <input type="text" name="CompanyName" class="ipt-t ipt-t-dft" maxlength="100" /> 
    <input type="file" name="upFile" id="upFile" /> 
    <div onclick="upFile.click();" class="btn btn-dft btn-dft-impt"> 
      <span>dddd</span> 
    </div> 
    </body>
    </html>
      

  6.   

    另外,注意浏览器设置不同,得到的结果不同http://www.junstyle.com.cn/upload/fakepath.png