我在JS中使用setInterval来选择表单中的下拉菜单。根据选择,我想显示1个购买按钮或另一个。
我的问题是
这是我的JF
this.getReadableDatabase();
SQLiteDatabase db = null;
try {
db = ctx.openOrCreateDatabase(
DB,
SQLiteDatabase.OPEN_READWRITE, null);
ContentValues values = new ContentValues();
values.put(URL, url);
values.put(OBJECT, object);
values.put(TYPE, type);
// Inserting Row
db.insert(CACHE_TABLE_NAME, null, values);
db.close(); // Closing database connection
this.close();
} catch (Exception e) {
e.printstacktrace();
try {
db.close();
this.close();
} catch (Exception e) {
e.printstacktrace();
this.close();
}
}
}
这是我的HTML
setInterval (function() {
var auto_renew = $('#auto_renew').val();
if (auto_renew == 1) {
$'#subscription_purchase').css('display', 'none');
$('#normal_purchase').css('display', 'none');
} else {
$'#subscription_purchase').css('display', 'none');
$('#normal_purchase').css('display', 'inline');
}
}, 0)
必须有一种更聪明的方法来做到这一点......
答案 0 :(得分:0)
你走了,
$(document).ready(function(){
$('#auto_renew').on('change', function(){
var selected = $(this).val();
var subscriptionElm = $('#subscription_purchase');
var normalElm = $('#normal_purchase');
switch (selected) {
case '1':
subscriptionElm.show();
normalElm.hide();
break;
case '0':
subscriptionElm.hide();
normalElm.show();
break;
default:
subscriptionElm.hide();
normalElm.hide();
break;
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="auto_renew">
<option value="-1"></option>
<option value="1">Subscription Purchase</option>
<option value="0">Normal Purchase</option>
</select>
<br/><br/>
<div id="subscription_purchase" style="display:none;">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="a3" id="hiddentotal2" value="5.00">
<input type="submit" name="submit" value="PURCHASE SUB" />
</div>
<div id="normal_purchase" style="display:none;">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="amount" id="hiddentotal2" value="1">
<input type="submit" name="submit" value="PURCHASE NORM" />
</div>