简体   繁体   English

点击功能内的jQuery更改功能无法正常工作

[英]Jquery change function inside click function not working properly

I have selects with some values, and i want to remember value by clicking one of them and after change do something with this. 我选择了一些值,我想通过单击其中一个值来记住值,并在更改后用此值做一些事情。

 $("select[id^='zmieniaj']").click(function() {
      var poprz=$(this).val();
      $("select[id^='zmieniaj']").change(function(){
      ...
});
});

So im remembering clicked value in variable and i refer to it in change function. 所以我记得变量中的单击值,我在更改函数中引用它。 It works good when i click only once on select and made change in the same step. 当我只单击一次并在同一步骤中进行更改时,它的效果很好。 If i click few times it does not trigger change function imimmediately, but it remembers how many times i clicked and when i made change it acts crazy by making up for previous clicks. 如果单击几次,它不会立即触发更改功能,但是会记住我单击了几次,并且在进行更改时,它会通过弥补以前的单击而发疯。

How to do that, if CONDITION A-click and CONDITION B-change is made only then, and only once do what is in change function ?? 如果仅进行条件A单击条件B更改 ,并且更改功能只有一次,该怎么做?

Try something like 尝试类似

$("select[id^='zmieniaj']").focus(function () {
    var $this = $(this);
    $this.data('fvalue', $this.val());
}).change(function () {
    var $this = $(this),
        cval = $this.val(),
        pval = $this.data('fvalue');
});

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

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