2014-10-30 39 views
1

如果我使用css屬性display: none隱藏它,Safari不會打開元素!它適用於所有其他瀏覽器。Safari顯示:無

這裏是我的html:

<div id="f" class="btn">Select Image</div> 
<input type="file" id="file" style="display:none;" name='athletes_imageid' value="" /> 

現在,在我的jQuery我想通過點擊該 「選擇圖片」 <div>打開id="file"

$("#f").click(function() { 
    $("#file").click(); 
}); 
+0

是否'#F'有任何高度?嘗試給它一些高度 – 2014-10-30 07:57:33

+0

哈哈什麼是高度? – Orangutan 2014-10-30 07:59:10

+0

在div#f上使用'style =「height:10px」''屬性 – 2014-10-30 08:11:29

回答

0

設置類型= '隱藏' 唐不使用風格。

**編輯:**

嘗試:

#file { 
    height: 0; 
    visibility: hidden; 
    width: 0; 
} 
+1

他正在嘗試打開文件對話框 – 2014-10-30 08:00:16

+0

我無法做到這一點,我的輸入打開一個文件選擇窗口上傳。 – Orangutan 2014-10-30 08:01:00

+0

啊,你可以嘗試可見性:隱藏,而不是設置一個高度和寬度爲0 :) – Paddy 2014-10-30 09:36:06

0

嘗試這個

<div id="f" class="btn">Select Image 
    <input type="file" class="file" name='athletes_imageid' value="" /> 
</div> 

的風格

.btn{ 
    position: relative; 
} 
.file{ 
    position: absolute; 
    top: 0; 
    bottom: 0; 
    left: 0; 
    bottom: 0; 
    opacity: 0; 
} 
+0

你知道你可以覆蓋邊距。對? – 2014-10-30 09:33:22

+0

這不是CSS的意義上的邊際,但我只是重試,它已經消失了,所以我的錯對不起(我刪除了無用的評論) – lapin 2014-10-30 09:45:37

+0

你可以upvote我的答案?如果它幫助你。 – 2014-10-30 09:50:33

0

你可以僅僅刪除display:none,並添加以下這是CSS最簡單和跨瀏覽器的方式,我知道該怎麼做的伎倆:

#file { 
    height: 0; 
    position: absolute; 
    width: 0; 
} 

,因爲它似乎不支持我的Safari瀏覽器版本反正我不爲您提供的jsfiddle;)

相關問題