我正在处理一个表单,其中选择值正在根据点击进行更改
当我点击jQuery(".monthsele").click(function() {
var monthval = jQuery(this).find("span").attr('umval');
jQuery("#formselect #mons option:selected").remove();
jQuery("#formselect #mons option[value=" + monthval + "]").attr('selected', 'selected');
setTimeout(function() {
jQuery('form#formselect').submit();
}, 1000);
});
时,我的选择选项值正在改变,但它正在提交带有之前选择选项值的表单。我希望我的新价值能够提交。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<form name="formselect" id="formselect" method="post" action="">
<select id="mons" name="mons">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<button type="submit" name="formselect_form" id="formselect_form" class="btn btn-default">submit</button>
</form>
<h3 class="col-sm-4 monthsele"><span umval="2" class="pull-left">2</span></h3>
private String [] arrFilePaths=new String[4];
答案 0 :(得分:1)
而不是:
jQuery("#formselect #mons option[value="+monthval+"]").attr('selected', 'selected');
试
jQuery("#formselect #mons").val(monthval).change();
检查此示例:
jQuery(".monthsele").click(function() {
var monthval = jQuery(this).find("span").attr('umval');
jQuery("#formselect #mons").val(monthval).change();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form name="formselect" id="formselect" method="post" action="">
<select id="mons" name="mons">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<button type="submit" name="formselect_form" id="formselect_form" class="btn btn-default">submit</button>
</form>
<h3 class="col-sm-4 monthsele"><span umval="2" class="pull-left">2</span></h3>