2

我正在使用jQuery驗證引擎插件pos-absolute。jquery驗證引擎用於文件上傳驗證當我使用jasny引導文件上傳

我有一個插件,隱藏輸入類型=「文件」,並用一個按鈕替換它。

這工作正常,如果沒有選擇文件,然後jQuery驗證引擎沒有顯示彈出消息,它提交成功。

我遇到的問題是沒有彈出窗口顯示,並且當字段爲空時不驗證文件上傳字段。

這是我硬編碼的HTML:

<div class="fileupload fileupload-new" data-provides="fileupload" id="question_choice_image" style="display:none;"> 
<div class="fileupload-preview thumbnail" id="question_choice_image" style="width: 70px; height: 30px;"></div> 
<div > 
<span class="btn btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists">Change</span><input type="file" data-validation-engine="validate[required]" data-errormessage-value-missing="Question is required!" name="question_choice_img" /></span> 
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a> 

所以結構是存在的,所以我可以驗證文件上傳提交。

回答

0

而不是用「display:none;」來隱藏它 試圖使其可見,但移動它的邊緣如:-9999px .... 我的解決方案是: 我設置它絕對和高度:0px; width:0px; line-height:0px;字體大小:0像素; 並將其置於父容器的左上角,並且我收到了所有提醒;)

特技不是爲了「隱藏」原始輸入字段,因爲警報不是在顯示器上觸發:無字段...希望它有幫助.. ..