判断表单提交是否为空 | isEmpty()函数的封装

提交表单,传的都是字符串。即使当你提交的内容为空,它任然返回一个空字符串。注意注意!

所以要封装一个函数来判断究竟是否为空值。

function isEmpty(val){
    if(typeof val == "undefined" || val == null || val ==""){
        return true;
    }
    else{
        return false;
    }
}

当内容为空时返回true,非空时则返回false。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是用 C 语言改写,并去掉重复数的代码: #include <stdio.h> #include <stdlib.h> struct ListNode { int val; struct ListNode *next; }; struct ListNode* mergeList(struct ListNode* l1, struct ListNode* l2){ struct ListNode* dummy = (struct ListNode*)malloc(sizeof(struct ListNode)); // 新建一个虚拟头节点 dummy->val = 0; dummy->next = NULL; struct ListNode* cur = dummy; while (l1 && l2) { if (l1->val <= l2->val) { cur->next = l1; l1 = l1->next; } else { cur->next = l2; l2 = l2->next; } cur = cur->next; } if (l1) cur->next = l1; // 将剩余的节点加入到新链中 if (l2) cur->next = l2; return dummy->next; } int main() { int n, m, num; scanf("%d%d", &n, &m); struct ListNode* l1 = (struct ListNode*)malloc(sizeof(struct ListNode)); struct ListNode* l2 = (struct ListNode*)malloc(sizeof(struct ListNode)); struct ListNode* p1 = l1; struct ListNode* p2 = l2; for (int i = 0; i < n; i++) { scanf("%d", &num); p1->next = (struct ListNode*)malloc(sizeof(struct ListNode)); p1->next->val = num; p1->next->next = NULL; p1 = p1->next; } for (int i = 0; i < m; i++) { scanf("%d", &num); p2->next = (struct ListNode*)malloc(sizeof(struct ListNode)); p2->next->val = num; p2->next->next = NULL; p2 = p2->next; } struct ListNode* res = mergeList(l1->next, l2->next); // 去除重复数 int hash[10001] = {0}; // 哈希,假设节点值范围在 [0, 10000] struct ListNode* cur = res; struct ListNode* pre = NULL; while (cur) { if (hash[cur->val]) { // 如果当前节点值已经出现过,则删除当前节点 pre->next = cur->next; free(cur); cur = pre->next; } else { // 如果当前节点值没有出现过,则将其加入哈希,并继续遍历下一个节点 hash[cur->val] = 1; pre = cur; cur = cur->next; } } // 输出结果 cur = res; while (cur) { printf("%d ", cur->val); cur = cur->next; } // 释放内存 cur = res; while (cur) { struct ListNode* temp = cur; cur = cur->next; free(temp); } return 0; }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值