尝试使用.split()时JS中未捕获的TypeError

时间:2016-02-10 00:39:54

标签: javascript split

为什么我一直得到

  

“未捕获的TypeError:segEnDia.split不是函数”

在这个例子中我想让它起作用吗?

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <executions>
                <execution>
                    <id>copy-fonts</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/generated-resources/static/fonts</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${project.build.directory}/unpacked/META-INF/resources/webjars/bootstrap/3.2.0/fonts</directory>
                                <includes>
                                    <include>**/*</include>
                                </includes>
                                <filtering>false</filtering>
                            </resource>
                            <resource>
                                <directory>${project.build.directory}/unpacked/META-INF/resources/webjars/font-awesome/4.5.0/fonts</directory>
                                <includes>
                                    <include>**/*</include>
                                </includes>
                                <filtering>false</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

谢谢!

1 个答案:

答案 0 :(得分:2)

segEnDia不是字符串而是数字。您必须将值转换为字符串。试试这个:

var cantidadDada = 1000;
var segEnDia = cantidadDada / 86400;
var segEnDiaSplit = ("" + segEnDia).split(".");