我有一个表单,我需要禁用文件选择/输入,直到文本输入和选择选项都不是空白和默认(分别)。
我有以下内容,我无法弄清楚未选择的部分:
<div class="form-group">
<div class="input-group col-md-6">
<input type="text" class="form-control" placeholder="Search by Asset ID" maxlength="64" class="form-control" id="imageid" name="imageid"> <span class="input-group-btn">
<button class="btn btn-default image-search" type="button">Search</button>
</span>
</div>
<div class="search-results"></div>
</div>
<div class="form-group">
<label for="image">Select Asset Type:</label>
<select id='crop' class="btn btn-default" data-toggle="dropdown">
<option value="default">Choose Type</option>
<option value="now">Now</option>
<option value="livefeeds">Live Feeds</option>
</select>
</div>
<div class="form-group">
<label for="imageid">Select an image</label>
<input type="file" name="file" class="btn btn-default form-control" id="file"
accept="image/jpg, image/png, image/jpeg" />
</div>
if ($("#imageid").val() == '' && $("#crop default").is(':selected')) {
$("#file").attr("disabled", "true");
} else if ($("#imageid").val() != '' && $("#crop").val() != "default") {
$("#file").attr("disabled", "false");
}
JSFiddle:link
答案 0 :(得分:2)
希望这会有所帮助:
function checkForInputs(){
var filledUp = $("#imageid").val() != '' && $("#crop").val() != "default";
if (!filledUp) {
$("#file").attr("disabled", true);
} else if (filledUp) {
$("#file").attr("disabled", false);
}
}
$("#imageid").keyup(function(){ checkForInputs(); });
$("#crop").change(function(){ checkForInputs(); });
checkForInputs();