简体   繁体   English

jQuery Mobile中的翻转切换开关错误

[英]Error with flip toogle switch in Jquery Mobile

I need to made a calculator for an app with Jquery Mobile, but it doesn´t work whit the flip toogle switch, this is my script: 我需要为使用Jquery Mobile的应用程序制作一个计算器,但是如果使用扳动翻盖开关,它就无法工作,这是我的脚本:

<script type="text/javascript">
function dosis() {
    $peso = $('#peso').get(0).value
    $dosis = $('#dosis').get(0).value
    $concentracion = $('#concentracion').get(0).value

    if ($peso=='' || $dosis=='') {
        alert('Debes llenar los campos de Peso y Dosis');
        exit;
    }

    if ($concentracion=='') {
    $resultado = ($peso * $dosis);
    $resultado = Math.round($resultado*Math.pow(10,2))/Math.pow(10,2);
    $('#resultado').html('Debes administar <span style="color: #009A8F; font-size: 30px;">' + $resultado + '</span> mg. de farmaco.<br />');
    } 

    else {
        $("#flipswitch").on("change", function () {
                if ($(this).val() == "off")

    $resultado = ($peso * $dosis);
    $resultado = Math.round($resultado*Math.pow(10,2))/Math.pow(10,2);
    $resultado2 = (($peso * $dosis) / ($concentracion * 10));
    $resultado2 = Math.round($resultado2*Math.pow(10,2))/Math.pow(10,2);

    $('#resultado').html('Debes administar <span style="color: #009A8F; font-size: 30px;">' + $resultado + '</span> mg. de farmaco.<br /> Dedes administar <span style="color: #009A8F; font-size: 30px;">'+ $resultado2 + '</span> ml. del producto.');

            else {

    $resultado = ($peso * $dosis);
    $resultado = Math.round($resultado*Math.pow(10,2))/Math.pow(10,2);
    $resultado2 = (($peso * $dosis) / ($concentracion));
    $resultado2 = Math.round($resultado2*Math.pow(10,2))/Math.pow(10,2);

    $('#resultado').html('Debes administar <span style="color: #009A8F; font-size: 30px;">' + $resultado + '</span> mg. de farmaco.<br /> Dedes administar <span style="color: #009A8F; font-size: 30px;">'+ $resultado2 + '</span> ml. del producto.');
    exit;
}};
});</script>

Something is wrong with the script? 脚本出了点问题?

There are several errors in your code. 您的代码中有几个错误。

A few practical advice: 一些实用建议:

  1. Use an integrated development environment (IDE) to write better code. 使用集成开发环境(IDE)编写更好的代码。 See for instance this thread for suggestions. 例如,请参见该线程以获取建议。 IDEs have built-in error-checking and let you know where and what you code misses. IDE具有内置的错误检查功能,可让您知道代码遗漏的位置和内容。
  2. You might also want to use an online validator, eg http://www.jslint.com/ 您可能还想使用在线验证器,例如http://www.jslint.com/
  3. As Eihwas indicates, correct code layout will help a lot when other people are to read your code. 正如Eihwas指出的那样,当其他人要阅读您的代码时,正确的代码布局将大有帮助。 You can fix your code layout with tools like this, http://jsbeautifier.org/ , great tools, but it's better to learn to code correctly. 您可以使用http://jsbeautifier.org/之类的出色工具来修复代码布局,但是最好学习正确编码。 It is way easier to read and maintain well-written code. 这是更容易阅读和维护编写良好的代码的方法。

If your code still does not work, please elaborate your question. 如果您的代码仍然无法使用,请详细说明您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM