我想在我的應用程序中使用圖像作爲文件類型按鈕,但點擊圖像功能正在執行,但按鈕document.getElementById("myFile").click();
未執行。我的代碼有什麼問題?問題點擊事件
HTML:
<div align="center">
<a href="#" id="other-color" onClick='loadFile()'><img style="width:75px;height:auto" src="icons/slr-camera-2-256.png"/></a>
<input type="file" id="myFile" style="display:none" />
</div>
腳本:
function loadFile()
{
alert("test");
document.getElementById("myFile").click();
}
同時取出'html5'和'jQuery'標籤,因爲這個問題不有 –
你的代碼適合我!它應該是別的 – Konst
@Precious如果使用jQuery是可以接受的,請添加標籤。你可以嘗試使用jQuery來選擇元素,如:$('#myFile')。click()' – Kabie