點擊添加附件沒反應
老師,我點擊添加附件之后,沒有任何反應,瀏覽器底部出現一條javascript:void(0),并不出現文件選擇框,求解
<?php require_once?'../include.php'; checkLogined(); $rows?=?getAllCate(); //print_r($rows); if(!$rows){ alertMes("沒有相應分類,請先添加","addCate.php"); } ?> <!doctype?html> <html> <head> <meta?charset="utf-8"> <title>-.-</title> <link?href="./styles/global.css"??rel="stylesheet"??type="text/css"?media="all"?/> <script?type="text/javascript"?charset="utf-8"?src="../plugins/kindeditor/kindeditor.js"></script> <script?type="text/javascript"?charset="utf-8"?src="../plugins/kindeditor/lang/zh_CN.js"></script> <script?type="text/javascript"?src="./scripts/jquery-1.6.4.js"></script> <script> ????????KindEditor.ready(function(K)?{ ????????????????window.editor?=?K.create('#editor_id'); ????????}); ????????$(document).ready(function(){ ???????? $("#selectFileBtn").click(function(){ ???????? $fileField?=?$('<input?type="file"?name="thumbs[]"/>'); ???????? $fileField.hide(); ???????? $("#attachList").append($fileField); ???????? $fileField.trigger("click"); ???????? $fileField.change(function(){ ???????? $path?=?$(this).val(); ???????? $filename?=?$path.substring($path.lastIndexOf("\\")+1); ???????? $attachItem?=?$('<div?class="attachItem"><div?class="left">a.gif</div><div?class="right"><a?href="#"?title="刪除附件">刪除</a></div></div>'); ???????? $attachItem.find(".left").html($filename); ???????? $("#attachList").append($attachItem); ???????? }); ???????? }); ???????? $("#attachList>.attachItem").find('a').live('click',function(obj,i){ ???????? $(this).parents('.attachItem').prev('input').remove(); ???????? $(this).parents('.attachItem').remove(); ???????? }); ????????}); </script> </head> <body> <h3>添加商品</h3> <form?action="doAdminAction.php?act=addPro"?method="post"?enctype="multipart/form-data"> <table?width="70%"??border="1"?cellpadding="5"?cellspacing="0"?bgcolor="#cccccc"> <tr> <td?align="right">商品名稱</td> <td><input?type="text"?name="pName"??placeholder="請輸入商品名稱"/></td> </tr> <tr> <td?align="right">商品分類</td> <td> <select?name="cId"> <?php?foreach($rows?as?$row):?> <option?value="<?php?echo?$row['id'];?>"><?php?echo?$row['cName'];?></option> <?php?endforeach;?> </select> </td> </tr> <tr> <td?align="right">商品貨號</td> <td><input?type="text"?name="pSn"??placeholder="請輸入商品貨號"/></td> </tr> <tr> <td?align="right">商品數量</td> <td><input?type="text"?name="pNum"??placeholder="請輸入商品數量"/></td> </tr> <tr> <td?align="right">商品市場價</td> <td><input?type="text"?name="mPrice"??placeholder="請輸入商品市場價"/></td> </tr> <tr> <td?align="right">商品慕課價</td> <td><input?type="text"?name="iPrice"??placeholder="請輸入商品慕課價"/></td> </tr> <tr> <td?align="right">商品描述</td> <td> <textarea?name="pDesc"?id="editor_id"?style="width:100%;height:150px;"></textarea> </td> </tr> <tr> <td?align="right">商品圖像</td> <td> <a?href="javascript:void(0)"?id="selectFileBtn">添加附件</a> <div?id="attachList"?class="clear"></div> </td> </tr> <tr> <td?colspan="2"><input?type="submit"??value="發布商品"/></td> </tr> </table> </form> </body> </html>
2017-07-06
方法試了,不可以
2017-01-29
方案一:trigger("click")寫在change事件后
方案二:
$("#selectFileBtn").click(function(event) {
$fileFiled=$('<input type="file" name="thumbs[]"/>' );
$fileFiled.hide();
$("#attachList").append($fileFiled);
$fileFiled.trigger('click');
$fileFiled.change(function(event) {
//console.log("change");
$path=$(this).val();
$filename=$path.substring($path.lastIndexOf("\\")+1);
if($path!=""){
$attachItem=$('<div class="attachItem"><div class="left">a.gif</div><a href="javascript:void(0)" title="刪除附件">刪除</a></div>');
$attachItem.find(".left").html($filename);
$("#attachList").append($attachItem);
$a=$("#attachList>.attachItem").find("a");
//console.log("第二次算a數量為:"+$a.length);
$a.click(function(){
? ?//console.log("觸發了click事件");
? ?$(this).parents('.attachItem').prev('input').remove();
$(this).parents('.attachItem').remove();
})
}
});
//$fileFiled.trigger('change'); ?//egde 瀏覽器不寫這句不能顯示?!
$a=$("#attachList>.attachItem").find("a");
if($a.length==0){
//console.log("a數量為零,手動觸發change事件");
$fileFiled.trigger('change');
}
//event.stopPropagation();
});
即手動模擬觸發一下change
ps:我也不知道為什么,但是測試后發現好像egde瀏覽器在trigger("click")觸發后后續的代碼就不會執行,因此,選擇文件完成后,才會執行后續代碼,因此對于change事件而言,相當于沒有change
2016-10-13
大神請問你是怎么解決的呢?能說下嗎?謝謝
2016-03-26
求解
????
2015-12-22
如何解決的?
2015-10-03
以解決?