jQuery Blueimp File Upload组件未触发问题咨询
Hey there, let's dig into why your Blueimp File Upload component isn't triggering properly—looks like a couple of small issues in your code are causing the file input to be disabled on load. Here's what's going wrong and how to fix it:
1. Mismatched Quotes in Selector
First up, you've got a syntax error in your jQuery selector:
$("#files') // 👈 Double quote opens, single quote closes—mismatch!
This invalid syntax stops jQuery from finding your file input element entirely, which means the fileupload() initialization never runs correctly. Fix it by using matching quotes:
$("#files") // Or $('#files')—just keep the quote style consistent
2. Unintended Disabled State from Browser Support Check
Your code includes this line that disables the input if $.support.fileInput returns false:
.prop('disabled', !$.support.fileInput)
In many cases, this check might return false unexpectedly (or you might not even need this compatibility restriction). If you want the file input to be enabled regardless of browser support (reasonable for most modern browsers), simply remove this line and the associated parent class addition.
Corrected Full Code
Here's your fixed code with the above issues addressed:
<script> $(function() { $("#files").fileupload({ url: "uploadhandler.php", dataType: 'text', autoUpload: false, singleFileUploads: false, replaceFileInput: false, add: function (e, data) { alert("inside add"); } }); // Removed lines that disabled the input based on support check }); </script>
Extra Quick Checks
- Double-check that your file input element has the exact
id="files"attribute (no typos!). - If you do need to keep the browser support check, test what value
$.support.fileInputreturns by addingconsole.log($.support.fileInput);right before the initialization—this will help you confirm if the check is working as intended.
内容的提问来源于stack exchange,提问作者Jenz

