如何在jQuery中从一个函数传递变量到另一个函数。

huangapple go评论64阅读模式
英文:

How to pass a variable from one function to another function jquery

问题

$('input[name="choix_livraison"]').on('click', function() {
      var livraison = $(this).attr('data-nom')
      
      console.log("verification si variable passe",livraison)

 });
 
$("#cb_Nom").keyup(function() {
     console.log("verification si variable passe",livraison)
});
英文:

hello I would like my delivery variable created in the first function to be used in the second function

$('input[name="choix_livraison"]').on('click', function() {
      var livraison = $(this).attr('data-nom')
      
      console.log("verification si variable passe",livraison)

 });
 
$("#cb_Nom").keyup(function() {
     console.log("verification si variable passe",livraison)
});

答案1

得分: 2

var livraison;

$('input[name="choix_livraison"]').on('click', function() {
    livraison = $(this).attr('data-nom');
      
    console.log("verification if variable is passed", livraison);
});

$("#cb_Nom").keyup(function() {
    console.log("verification if variable is passed", livraison);
});
英文:
var livrasion;

$('input[name="choix_livraison"]').on('click', function() {
    livraison = $(this).attr('data-nom')
      
    console.log("verification si variable passe",livraison)
});

$("#cb_Nom").keyup(function() {
    console.log("verification si variable passe",livraison)   
});

You can declare it as a global variable and since JQuery runs on the client side you don't have to worry about it being over written by other users.

huangapple
  • 本文由 发表于 2023年2月8日 22:16:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75387073.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定