<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>WeStudio技术社区 - JavaScript脚本</title>
    <link>https://www.wareexpress.com/forum/forum.php?mod=forumdisplay&amp;fid=40</link>
    <description>Latest 20 threads of JavaScript脚本</description>
    <copyright>Copyright(C) WeStudio技术社区</copyright>
    <generator>Discuz! Board by Comsenz Inc.</generator>
    <lastBuildDate>Fri, 03 Apr 2026 19:54:22 +0000</lastBuildDate>
    <ttl>60</ttl>
    <image>
      <url>https://www.wareexpress.com/forum/static/image/common/logo_88_31.gif</url>
      <title>WeStudio技术社区</title>
      <link>https://www.wareexpress.com/forum/</link>
    </image>
    <item>
      <title>为什么toFixed()方法报错了？</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=6950</link>
      <description><![CDATA[在我们的日常开发工作中，可能经常会使用到 toFixed()方法来保留浮点数的小数位数，但是需要注意的是Number.toFixed()方法返回的值类型为string（字符串）

如 var a = 3.1415926; 我们要保留两位小数并显示到标签上，那 ...]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
<enclosure url="https://www.wareexpress.com/forum/data/attachment/forum/202211/22/095232rx5lh2t3t4675mt3.png" length="110222" type="image/jpeg" />      <pubDate>Tue, 22 Nov 2022 02:10:28 +0000</pubDate>
    </item>
    <item>
      <title>如何将16进制数组的内容转换成ASCII字符串？</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=6934</link>
      <description><![CDATA[比如接收到的数组内容为  [0x32, 0x33, 0x36, 0x2E, 0x36, 0x38]， 如何让它显示为“236.68” ？ 
我们可以通过 util.cast控件的arrayToUtf8()方法来转换，如下：]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
<enclosure url="https://www.wareexpress.com/forum/data/attachment/forum/202211/03/111810gtoftfceefzt4hoa.png" length="108884" type="image/jpeg" />      <pubDate>Thu, 03 Nov 2022 03:19:01 +0000</pubDate>
    </item>
    <item>
      <title>数组的截取和合并</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=6886</link>
      <description><![CDATA[1、数组的截取：使用slice()方法，可从已有的数组中返回选定的元素，但是它并不会改变原始数组
Array.slice(start, end)返回一个新的数组，包含从 start（包括该元素） 到 end （不包括该元素）的数组对象中的元素


2、数组的合并：使用concat() 方法，用于连接两个或 ...]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Tue, 06 Sep 2022 09:25:30 +0000</pubDate>
    </item>
    <item>
      <title>位操作</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=6885</link>
      <description><![CDATA[1、获取某位：移位和与操作
2、设置某位为0：用与操作

3、设置某位为1：用或操作]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Tue, 06 Sep 2022 04:56:03 +0000</pubDate>
    </item>
    <item>
      <title>如何使用log10()方法？</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=6883</link>
      <description><![CDATA[在WeStudio使用的JavaScript版本中并没有包含Math.log10()方法，但是里面包含了Math.log()方法，所以我们可以在全局代码里面自己定义一个方法来封装一下log10()



模拟运行一下效果

 ...]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
<enclosure url="https://www.wareexpress.com/forum/data/attachment/forum/202209/05/171132kh252lowop75hhlw.png" length="96133" type="image/jpeg" />      <pubDate>Mon, 05 Sep 2022 09:12:02 +0000</pubDate>
    </item>
    <item>
      <title>如何把科学计数法转换为十进制表示？</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=6630</link>
      <description><![CDATA[将下面的转换方法放到全局代码(init.js)中定义
在按钮的onRelease事件方法中进行测试

测试结果：]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
<enclosure url="https://www.wareexpress.com/forum/data/attachment/forum/202207/12/173408gdo3bobc6j40fo0f.png" length="13148" type="image/jpeg" />      <pubDate>Tue, 12 Jul 2022 09:28:36 +0000</pubDate>
    </item>
    <item>
      <title>字符串的截取</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=6629</link>
      <description><![CDATA[JavaScript 语法中提供了两人个截取字符串的方法，一个是 substring(), 另外一个是 substr()

1、 substring() 提取字符串中两个指定的索引号之间的字符，方法返回的子串包括 开始 处的字符，但不包括 结束 处的字符
语法
string.substring(from, to)


例如：字符串 \&quot;H ...]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Mon, 11 Jul 2022 02:21:08 +0000</pubDate>
    </item>
    <item>
      <title>如何将以字符串0开头的字符串转换成10进制数？</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=6415</link>
      <description><![CDATA[一般情况下我们把字符串转换成整数，可以使用JavaScript内部方法 parseInt()来转换，默认情况下它是按10进制转换的，如：

但是如果字符串是以0开头的，转换结果可能不是我们预期的10进制，如：


我们来看一下parseInt()方法的定义


所以为了正确地将‘0023’转换为10 ...]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Mon, 31 May 2021 07:06:18 +0000</pubDate>
    </item>
    <item>
      <title>有符号数和无符号数之间的相互转换</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=6412</link>
      <description><![CDATA[在JavaScript语法中，可以使用移位运算来转换。
无符号数转换有符号数，使用左移位：&gt;&gt; 0]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Fri, 07 May 2021 02:35:12 +0000</pubDate>
    </item>
    <item>
      <title>如何删除字符串中的多个字符？</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=925</link>
      <description><![CDATA[有时我们需要把一个字符串的某些字符删除或者替换掉，怎么办呢？可以借助 JavaScript本身字符串对象的replace方法来实现。

例如我们要去掉字符串\'A,B,C.D.E\&quot;F\&quot;G;H;J\'中的 . , \&quot; ; | [ ]  只需要把这几个字符替换为空字符即可:
在模拟器上模拟一下，结果如下：



 ...]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Tue, 02 Feb 2021 02:33:11 +0000</pubDate>
    </item>
    <item>
      <title>如何去掉util.arrayToHexString返回的字符串中的所有空格？</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=863</link>
      <description><![CDATA[如果串口收到一串数据 0x61 0x61 0x63 0x64, 我们想让它以16进制的形式显示，并且不含空格 (可以使用 stringObject.replace(regexp/substr,replacement))

var data = [0x61, 0x62, 0x63, 0x64];
如果我们直接显示的话，它是以逗号分隔的10进制的字符串 \&quot;97,98,99,100\&quot;
 ...]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Thu, 21 Jan 2021 01:48:20 +0000</pubDate>
    </item>
    <item>
      <title>如何去掉字符串最后的一个字符？</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=727</link>
      <description><![CDATA[比如我们通过扫码枪输入内容时，字符串的最后一个字符是一个回车符\'\\n\', 我们如果把它去掉呢？可以使用JavaScript字符串的substr方法 stringObject.substr(start,length)

var content = \'扫码结果:\' + device.keyboard.getString();
 content = content.substr(0, cont ...]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Tue, 19 Jan 2021 10:57:23 +0000</pubDate>
    </item>
    <item>
      <title>如何将10进制转换为16进制，不够2位16进制数自动补0？</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=64</link>
      <description><![CDATA[// 自定义一个方法d2h, 将10进制转换为16进制，不够2位16进制数自动补0d2h = function(d) {    var s = (+d).toString(16);    if(s.length &lt; 2) {        s = \'0\' + s;    }    return s;};
测试：
模拟运行：]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Sat, 12 Dec 2020 06:17:47 +0000</pubDate>
    </item>
    <item>
      <title>急！！！请问GLE-050的板子GPIO问题！！！！！</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=38</link>
      <description><![CDATA[前段时间买了一个GLE-050屏幕，现在有一个需求，想让GPIO1输出一个高电平，然后2秒后再输出一个低电平，请问技术服务大神，这个怎么实现呢？脚本里有延时函数吗？感谢！！！]]></description>
      <category>JavaScript脚本</category>
      <author>LZQ</author>
      <pubDate>Wed, 22 Jul 2020 03:54:59 +0000</pubDate>
    </item>
    <item>
      <title>如何解析JSON</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=36</link>
      <description><![CDATA[ExpOS 1.3.4版本开始增加了对JSON的解析，下面举例说一下使用方法

假如我们通过访问http控件访问网络，服务器返回下面格式的JSON字符串
如何读取里面每个字段的内容呢？我们可以使用util的jsonToJsObject方法把JSON转换成JS对象，代码如下：
反过来，如果我们已经有一 ...]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Tue, 07 Jul 2020 11:18:10 +0000</pubDate>
    </item>
    <item>
      <title>CRC查表法计算</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=28</link>
      <description><![CDATA[如果我们已经拿到一个C语言版本的CRC查表算法，如果转换成JS版本呢？下面举例说明一下:

CRC 校验算法及函数
转换成JavaScript来实现：]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Tue, 16 Jun 2020 05:54:30 +0000</pubDate>
    </item>
    <item>
      <title>为什么两个变量相加变成字符串相加了？</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=24</link>
      <description><![CDATA[比如下面的代码，我们希望把变量pi取小数点后两位再跟变量a相加, 把结果（3.14 + 100 等于 103.14）显示在界面标签label上，但是实际显示的结果是：1003.14

为什么结果不是我们预期的？问题在于上面的第3行代码: 


toFixed()方法返回的结果是一个字符串，所以变量pi变 ...]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Fri, 29 May 2020 02:25:11 +0000</pubDate>
    </item>
    <item>
      <title>利用eval()方法批量设置控件属性</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=21</link>
      <description><![CDATA[有时我们需要对界面上多个相同类型的控件属性进行修改，我们除了一行一行代码对他们进行修改，还有没有更好的办法？下面就来介绍下怎么利用JavaScript的eval方法来实现。


下面我们举例说明一下eval怎么使用：如下图，页面上有4个按钮，在页面onLoad的时候把它们初始化 ...]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Thu, 21 May 2020 01:15:22 +0000</pubDate>
    </item>
    <item>
      <title>字符串和数字之间的转换</title>
      <link>https://www.wareexpress.com/forum/forum.php?mod=viewthread&amp;tid=3</link>
      <description><![CDATA[[*]数组转换成字符串
如 var data = [0x61, 0x62, 0x63, 0x64]; 转换成字符串 \'abcd\'ui.main.label.text = util.arrayToUtf8(data); // 使用util.arrayToUtf8方法

[*]数字转换为16进制字符
如 var data = [0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff];将第2个元素0xcc显示成 ...]]></description>
      <category>JavaScript脚本</category>
      <author>hixon</author>
      <pubDate>Thu, 10 Oct 2019 04:54:08 +0000</pubDate>
    </item>
  </channel>
</rss>