Onclick没有在firefox中工作 [英] Onclick not working in firefox

查看:43
本文介绍了Onclick没有在firefox中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我有一个小编码,使用javascript将上传的文件路径复制到文本框中。它在IE中运行良好,但是没有在firefox中触发。



Hi all i have a small coding to copy the uploaded file path to a textbox using javascript. Its working fine in IE but onclick not firing in firefox.

<html>
<body>

<form method="post" action="<?php echo($_SERVER['PHP_SELF']);?>" name="form1" >
<label for="file">Filename:</label>
<input type="file" name="file1" id="file" ><br>
<input type="text" name="txtH" id="txtH"/>
<input type="button" name="submit" value="Submit" id="btnSubmit" onclick="fun()">

<script type="text/javascript">
function fun()
{
	document.getElementById('txtH').value=document.getElementById('file1').value;
	alert("hai");
}


</script>
</form>

</body>
</html> 

推荐答案

_SERVER ['PHP_SELF']);?> 名称 = form1 >
< 标签 = file > 文件名:< / label >
< 输入 类型 = file name = file1 id = file > < br <小号pan class =code-keyword>>
< 输入 type = text name = txtH id = txtH / >
< 输入 < span class =code-attribute> type = button name = 提交 value = 提交 id = btnSubmit onclick = fun( ) >

< script type = text / javascript >
function fun()
{
document .getElementById(' txtH')。value = document .getElementById(' file1')。value;
alert( hai);
}


< / script >
< < span class =code-leadattribute> / form >

< ; / body >
< / html >
_SERVER['PHP_SELF']);?>" name="form1" > <label for="file">Filename:</label> <input type="file" name="file1" id="file" ><br> <input type="text" name="txtH" id="txtH"/> <input type="button" name="submit" value="Submit" id="btnSubmit" onclick="fun()"> <script type="text/javascript"> function fun() { document.getElementById('txtH').value=document.getElementById('file1').value; alert("hai"); } </script> </form> </body> </html>


你在这行中有错误...

You have error in this line...
document.getElementById('txtH').value = document.getElementById('file1').value;



您正在访问Fil e上传者的路径由 getElementById(''file1''),但id不是''file1'',它是''file'',如下所示...


You are accessing the File Uploader''s path by getElementById(''file1''), but the id is not ''file1'', it is ''file'' as per below...

<input type="file" name="file1" id="file"></input>





将函数更改为以下代码,它将起作用。



Change the function to the below code, it will work.

function fun()
{
    document.getElementById('txtH').value=document.getElementById('file').value;
    alert("hai");
}


这篇关于Onclick没有在firefox中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆