将jQuery函数参数定义为字符串

Defines jQuery function parameter as string

本文关键字:字符串 定义 参数 jQuery 函数      更新时间:2024-04-27

我想问一个简单的问题,但我只是在网上搜索,却找不到答案。

功能项(条形码)

当条形码从零开始时,它将转换为int并删除第一个零,例如0123456,条形码将在函数中更改为123456。如何修复?

谢谢你。。抱歉我的英语不好

在将params传递给函数时,需要引用params:以下是示例:

item(000001) // this will trim your value because it's numeric value and input param will be numeric
item('000001') or item("000001") // in this case you will get full string with leading zeros

你需要这样的东西吗?

function item(barcode)
{
   if (barcode.charAt(0) == 0)
   {
       barcode = parseInt(barcode);
   }
   return barcode;
}