|zyciis| 如何在外部调用input file的click事件,为什么他的value不是显示的value呢?

zyciis281 2010-02-22 02:59:21
<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
要如何正确取值

谢谢

...全文
90 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2010-02-23
  • 打赏
  • 举报
回复
另外,注意浏览器设置不同,得到的结果不同

http://www.junstyle.com.cn/upload/fakepath.png

shan1119 2010-02-22
  • 打赏
  • 举报
回复
<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>
孟子E章 2010-02-22
  • 打赏
  • 举报
回复
可参考
http://topic.csdn.net/u/20091222/00/2da91ff1-9bb2-431c-8ddf-bb3011d7efbe.html?946
的方法
zyciis281 2010-02-22
  • 打赏
  • 举报
回复
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;
}
}
lure2222 2010-02-22
  • 打赏
  • 举报
回复
你把这个帖出来Tools.previousSibling(this)要不看不出来啊
shan1119 2010-02-22
  • 打赏
  • 举报
回复
<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>

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧