1

我正在尝试检查textarea内部是否没有输入任何内容或此代码存在默认值:

 if ($("#ipt-content").val() == '' && $("#ipt-content").val() == defaultValue) {
        $("#ipt-content").addClass("ipt-error");
        valid = false;
        emptyFields = true;
    } else {
        $("#ipt-content").removeClass("ipt-error");
    }

不幸的是,代码不起作用。你们能帮帮我吗?

4

2 回答 2

6

&&是逻辑与。你想要||,逻辑或。

于 2013-08-08T12:59:16.187 回答
2

如果您的默认值为line和 condition required || (逻辑或)然后更改您的代码如下:

 var defaultValue="line";
  if ($("#ipt-content").val() == '' || $("#ipt-content").val() == defaultValue) {
        $("#ipt-content").addClass("ipt-error");
        valid = false;
        emptyFields = true;
    } else {
        $("#ipt-content").removeClass("ipt-error");
 }
于 2013-08-08T13:03:35.160 回答