我尝试启用/禁用按钮状态,直到用户选择4个选择框。
我基于这个解决方案:LINK来自LINK,但就我而言,我无法让它发挥作用。这是我的小提琴: http://jsfiddle.net/ http://jsfiddle.net/marekandrzejak/nYCz6/,我做错了什么?
HTML:
<form action="classes/script.php" method="POST" name="pricelist" style="float:left;">
<div class="price_list option">
<label for="choose_currency">Wybierz walutę</label>
<select id="choose_currency" name="choose_currency">
<option value="" selected="selected">Wybierz...</option>
<option value="1">PLN</option>
<option value="<? echo $obj->getGBPRate() ?>">GBP</option>
<option value="<? echo $obj->getEurRate() ?>">EUR</option>
<option value="<? echo $obj->getUSDRate() ?>">USD</option>
</select>
</div>
<div class="price_list option">
<label for="vat">Podatek VAT</label>
<select id="vat" name="vat">
<option value="" selected="selected">Wybierz...</option>
<option value="23">23%</option>
<option value="0">0% WDT</option>
</select>
</div>
<div class="price_list option">
<label for="discount">Rabat</label>
<select id="discount" name="discount">
<option value="" selected="selected">Wybierz...</option>
<option value="0">0%</option>
<option value="5">5%</option>
<option value="10">10%</option>
<option value="15">15%</option>
<option value="20">20%</option>
</select>
</div>
<div class="price_list option">
<label for="language">Język</label>
<select id="language" name="language">
<option value="" selected="selected">Wybierz...</option>
<option value="7">Polski</option>
<option value="1">Angielski</option>
</select>
</div>
<button class="button minibutton" id="pricelistBtn" type="submit" name="submit" value="Pobierz"><span class="mini_icon mini_icon_zapisz"></span>Pobierz</button>
脚本(头部):
$('#pricelistBtn').attr('disabled', 'disabled');
$(document).ready(
function updateFormEnabled(){
if (verifyAdSettings()) {
$('#pricelistBtn').attr('disabled', '');
} else {
$('#pricelistBtn').attr('disabled', 'disabled');
}
function verifyAdSettings() {
if ($('#choose_currency').val() != '' && $('#vat').val() != '' && $('#discount').val() != '' && $('#language').val() != '') {
return true;
} else {
return false;
}
}
$('#choose_currency').change(updateFormEnabled);
$('#vat').change(updateFormEnabled);
$('#discount').change(updateFormEnabled);
$('#language').change(updateFormEnabled);
}
);
答案 0 :(得分:2)
$('#pricelistBtn').attr('disabled', 'disabled');
function updateFormEnabled(){
if (verifyAdSettings()) {
$('#pricelistBtn').removeAttr("disabled");
} else {
$('#pricelistBtn').attr('disabled', 'disabled');
}
}
function verifyAdSettings() {
if ($("#choose_currency option:selected").val() != '' && $("#vat option:selected").val() != '' && $('#discount option:selected').val() != '' && $('#language option:selected').val() != '') {
return true;
} else {
return false;
}
}
$(document).ready(function(){
$('#choose_currency').change(updateFormEnabled);
$('#vat').change(updateFormEnabled);
$('#discount').change(updateFormEnabled);
$('#language').change(updateFormEnabled);
});
答案 1 :(得分:0)
你去......
$('#pricelistBtn').attr('disabled', 'disabled');
$(document).ready(
function updateFormEnabled(){
if (verifyAdSettings()) {
$('#pricelis`enter code here`tBtn').attr('disabled', false); // set false over here not ''
} else {
$('#pricelistBtn').attr('disabled', 'disabled');
}
function verifyAdSettings() {
if ($('#choose_currency').val() != '' && $('#vat').val() != '' && $('#discount').val() != '' && $('#language').val() != '') {
return true;
} else {
return false;
}
}
$('#choose_currency').change(updateFormEnabled);
$('#vat').change(updateFormEnabled);
$('#discount').change(updateFormEnabled);
$('#language').change(updateFormEnabled);
}
);