“SKU validation with jQuery” 可以翻译为 “使用jQuery进行SKU验证”。

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

SKU validation with jquery

问题

I'm trying to make a validation SKU of this product, showing an alert message. Before, I had the same problem in another situation.

  1. <?php foreach($dvdLists as $key => $dvdList) { ?>
  2. <p class="sku-validator-dvd" style="visibility:hidden;"><?= $dvdList->sku ?></p>
  3. <?php } ?>

I tried to do the same solution with each function but doesn't work. I need to get each SKU product to make a comparison with the SKU input. Doing this that way I can only get the first one. The second forward doesn't work.

  1. $('#save_product').click(function(e){
  2. var skuInput = $.trim($('#sku').val());
  3. if(skuInput === $('.sku-validator-dvd').text()) {
  4. alert('This sku already exists');
  5. }
  6. });
英文:

I'm trying to make a validation SKU of this product, showing an alert message. Before, I had the same problem in another situation.

  1. <?php foreach($dvdLists as $key => $dvdList) { ?>
  2. <p class="sku-validator-dvd" style="visibility:hidden;"><?= $dvdList->sku ?></p>
  3. <?php } ?>

I tried to do the same solution with each function but doesn't work. I need to get each SKU product to make a comparison with the SKU input. Doing this that way I can only get the first one. The second forward doesn't work.

  1. $('#save_product').click(function(e){
  2. var skuInput = $.trim($('#sku').val());
  3. if(skuInput === $('.sku-validator-dvd').text()) {
  4. alert('This sku already exists');
  5. }
  6. });

答案1

得分: 2

Sure, here is the translated code part:

  1. $('#save_product').click(function(e){
  2. var skuInput = $.trim($('#sku').val());
  3. var skuExists = false;
  4. $('.sku-validator-dvd').each(function() {
  5. if (skuInput === $(this).text()) {
  6. skuExists = true;
  7. }
  8. });
  9. if (skuExists) {
  10. alert('This sku already exists');
  11. }
  12. });

Please let me know if you need any further assistance.

英文:
  1. $('#save_product').click(function(e){
  2. var skuInput = $.trim($('#sku').val());
  3. var skuExists = false;
  4. $('.sku-validator-dvd').each(function() {
  5. if (skuInput === $(this).text()) {
  6. skuExists = true;
  7. }
  8. });
  9. if (skuExists) {
  10. alert('This sku already exists');
  11. }
  12. });

Try this

huangapple
  • 本文由 发表于 2023年4月19日 18:55:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76053670.html
匿名

发表评论

匿名网友

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

确定