简体   繁体   English

jQuery的选择框的选择值不会改变结果

[英]jquery selected value of select box doesn't change result

I am trying to change the price result using .change on the storage select box by using the chrome console but what happens is that the price doesn't update. 我正在尝试通过chrome控制台在存储选择框中使用.change更改价格结果,但是发生的是价格没有更新。

I tried different other ways such as .click .trigger , still the select box switches between 16gb to 64gb back and forth but the price doesn't update. 我尝试了不同的其他方式,例如.click .trigger ,还是选择框16GB之间切换到64GB来回但价格不更新。 The price only updates when I manually change the select box value with the mouse. 价格仅在我用鼠标手动更改选择框值时更新。

What might be causing it not to switch? 是什么导致它不切换? Are there any alternative way to trigger the event by code? 是否有其他方法可以通过代码触发事件?

*** edit: this is not my code, I am just trying to understand how to get the data if the .click doesn't work through the console ***编辑:这不是我的代码,我只是想了解如果.click无法通过控制台工作,如何获取数据

在此处输入图片说明

The click() method is not necessary unless you explicitly want to trigger that event. 除非您明确想要触发该事件,否则click()方法不是必需的。

I've added a click() event listener and call on the last change here. 我添加了一个click()事件侦听器,并在这里调用最后一个更改。

 var select = $("#test_select"); select.on('click', function() { alert('click event'); }); setTimeout(function() { select.val("2"); }, 1000); setTimeout(function() { select.val("3"); }, 2000); setTimeout(function() { select.val("4"); }, 3000); setTimeout(function() { select.val("5").click(); }, 4000); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select name="test" id="test_select"> <option value="1" selected>1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> 

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

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