简体   繁体   English

jQuery 更改 select 值但不触发页面刷新

[英]jQuery changes select value but doesn't trigger page refresh

I created radio buttons on mobile that need to trigger the hidden select option in order for the page to refresh.我在手机上创建了单选按钮,需要触发隐藏的 select 选项才能刷新页面。 I have this code and it does change the select value on radio button click, but it doesn't refresh the page.我有这段代码,它确实在单击单选按钮时更改了 select 值,但它不会刷新页面。 When I click on it with my mouse the page refreshes with the selected option, but not when I do it just with jQuery. What can I do about it?当我用鼠标单击它时,页面会刷新并显示所选选项,但当我仅使用 jQuery 时则不会。我该怎么办?

Radio buttons:单选按钮:

<div class="m-box">
<input type="radio" class="sort-radio" name="r" value="featured">
<label>Featured Items</label>
<input type="radio" class="sort-radio" name="r" value="newest">
<label>Newest Items</label>
<input type="radio" class="sort-radio" name="r" value="bestselling"><label>Best 
Selling</label>
</div>

Select: Select:

<select class="form-select form-select--small " name="sort" id="sort" role="listbox">
    <option value="featured" selected="">Featured Items</option>
    <option value="newest">Newest Items</option>
    <option value="bestselling">Best Selling</option>
</select>

Code:代码:

$(".sort-radio").change(function () {                
$("#sort")
        .val($(this).val())
        .trigger('change');
});

I tried trigger('change') and change()...it does change the select option value, but how can I "fake" a mouse click in order for the whole page to refresh?我尝试了 trigger('change') 和 change()...它确实更改了 select 选项值,但我如何才能“假装”鼠标单击以使整个页面刷新?

$(".sort-radio").change(function() { $(".sort-radio").change(函数() {

$("#sort").val($(this).val()).trigger('click');

}); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM