简体   繁体   English

获取按钮值后执行操作

[英]Performing action after getting value of button

Can anyone tell me whats wrong with this code?谁能告诉我这段代码有什么问题? Ive already got it to alert the value of the button by using alert(y) and getting back 2437 but as soon as i put this condition statement in its not even giving me an alert.我已经让它通过使用 alert(y) 并返回 2437 来提醒按钮的值,但是一旦我把这个条件语句放在它甚至没有给我一个警报。

Im sure its something simple but im not seeing it.我确定它很简单,但我没有看到它。

jQuery(document).ready(function( $ ){
   if( $('body.single-product').length || $('body.single-product').length ){
   var x = document.getElementsByClassName("single_add_to_cart_button");
   var y = x[0].value;
   if y == 2437 {
     alert("Yes");
   }else{
     alert("No");
   }
  }
});

You have an error in your javascript code right here: if y == 2437您的 javascript 代码在这里有错误: if y == 2437

Correct it to this:将其更正为:

jQuery(document).ready(function( $ ){
 if( $('body.single-product').length || $('body.single-product').length ){
   var x = document.getElementsByClassName("single_add_to_cart_button");
   var y = x[0].value;
   if (y == 2437) {
     alert("Yes");
   }else{
     alert("No");
   }
 }
});

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

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