简体   繁体   English

检查选择字段和输入字段

[英]Check on selectfield and input field

I'm trying to do the following: 我正在尝试执行以下操作:

I have 1 select field and 1 input field. 我有1个选择字段和1个输入字段。 When these are filled out the sum of both has to be written to the span .result. 填写完这些值后,必须将两者的总和写入结果span .result。 (Immediately! So not off focus from input field etc.) (立即!因此请不要使焦点偏离输入字段等。)

I tried to use: 我尝试使用:

.on('click'
.on('change'
.on('blur'

and so on... 等等...

It only works on either input or selectfield but not on both at the same time. 它仅在输入或选择字段上起作用,而不能同时在两者上起作用。

To make this situation a bit more clear I added a fiddle 为了使这种情况更加清楚,我添加了一个小提琴

Use input and select events. 使用inputselect事件。

$('input, select').on('input select', function() {
  1. input event will be fired when the value of the input is changed either by manually entering the value or by copy-paste. 通过手动输入值或通过复制粘贴更改input值时,将触发input事件。
  2. select event will be fired on <select> when an <option> is selected. select <option>时,将在<select>上触发select事件。

Updated Fiddle 更新小提琴

 $('input, select').on('input select', function() { prijs_field = $('.prijs_field').val(); btw_field = $('.btw_field').val(); $('.result').html(prijs_field * btw_field); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <input type="text" class="prijs_field"> <select class="btw_field"> <option value="21">21%</option> <option value="6">6%</option> <option value="0">0%</option> </select> <span>the result is: </span><span class="result"></span> 

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

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