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

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

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.

<?php foreach($dvdLists as $key => $dvdList) { ?>   
    <p class="sku-validator-dvd" style="visibility:hidden;"><?= $dvdList->sku ?></p>
<?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.

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

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

<?php foreach($dvdLists as $key => $dvdList) { ?>   
    <p class="sku-validator-dvd" style="visibility:hidden;"><?= $dvdList->sku ?></p>
<?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.

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

答案1

得分: 2

Sure, here is the translated code part:

$('#save_product').click(function(e){
    var skuInput = $.trim($('#sku').val());
    var skuExists = false;
    $('.sku-validator-dvd').each(function() {
        if (skuInput === $(this).text()) {
            skuExists = true;
        }
    });
    if (skuExists) {
        alert('This sku already exists');
    }
});

Please let me know if you need any further assistance.

英文:
$('#save_product').click(function(e){
    var skuInput = $.trim($('#sku').val());
    var skuExists = false;
    $('.sku-validator-dvd').each(function() {
        if (skuInput === $(this).text()) {
            skuExists = true;
        }
    });
    if (skuExists) {
        alert('This sku already exists');
    }
});

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:

确定