jQuery OR ||操作员无法正常工作 [英] Jquery OR || operator not working

查看:70
本文介绍了jQuery OR ||操作员无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常简单的问题.或运算符不起作用,我正在尝试为标题和金额字段名称显示不同的功能.谢谢

it's a really simple question. The or operator is not working, i am trying to display a different function for both the title and amount field name. Thank you

$.each(x, function(i, field){
        if (field.name === "title" || "amount")
          {
            $( ".added-inquiry" ).find(".row:last-child").find(".column").find( ".added-inquiry-item").append(
                 '<input type="hidden" name="' + field.name + '" value="' + field.value + '"/>' +
                 '<span class="' + field.name + '">' + field.value + '</span>' + '<br>'
             );
        }

推荐答案

您要么必须重述类似条件,要么

You either have to restate the condition like

if (field.name === "title" || field.name === "amount")

或者您可以使用数组

if (["title","amount"].indexOf(field.name) > -1)

这篇关于jQuery OR ||操作员无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆