<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
要如何正确取值谢谢
<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
要如何正确取值谢谢
<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>
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;
}
}
http://topic.csdn.net/u/20091222/00/2da91ff1-9bb2-431c-8ddf-bb3011d7efbe.html?946
的方法
<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>