2013-04-04 64 views
0

我有一個函數,如果我把它叫做jquery事件按鍵按下,它就可以正常工作。但是如果我從另一個函數調用相同的函數,它不起作用。 這樣的調用乘法函數裏面添加。如何從Java腳本中的另一個函數調用函數

function add(){ 
    multiply(); 
    } 

的javascript:

 $(function(){ 

      var input = $('.input'), 
     bar = $('.bar'), 
     bw = bar.width(), 
     percent = bar.find('.percent'), 
     ps = percent.find('span'), 
     name = 'rotate'; 

     input.on('keydown', function(e){ 
     if (e.keyCode == 13){ 
      var t = $(this), val = t.val(); 
      if (val >=0 && val <= 100){ 
       var w = 100-val, pw = (bw*w)/100, 
        pa = { 
         height: w+'%' 
        }, 
        cw = (bw-pw)/2, 
        ca = { 
         left: cw 
        } 
       ps.animate(pa); 
       cs.text(val+'%'); 
       circle.animate(ca, function(){ 
        circle.removeClass(name) 
       }).addClass(name); 
      } else { 
       alert('range: 0 - 100'); 
       t.val(''); 
      } 
     } 
    }); 

}); 

HTML:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
     <html xmlns="http://www.w3.org/1999/xhtml"> 
     <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     <title>Horizontal bar graph with CSS3 and jQuery</title> 
     <link href="css/default.css" rel="stylesheet" type="text/css" /> 
     <script src="js/jquery.js" type="text/javascript"></script> 
     <script src="js/init.js" type="text/javascript"></script> 
     <script src="slider_scripts/cal_impact_on_clinic.js"></script> 
     <style> 
     #sliderValue140h{ position:absolute; 
      margin:0px 0px 0px 330px; 
      font-family: Myriad Pro,Normal,strong; 
      font-size: 16px; 
      border:none; 
      background-color:transparent; 
      color:#000; 
      } 

      #sliderValue150h{ position:absolute; 
      margin:0px 0px 0px 330px; 
      font-family: Myriad Pro,Normal,strong; 
      font-size: 16px; 
      border:none; 
      background-color:transparent; 
      color:#000; 
      }  

      #sliderValue160h{ position:absolute; 
      margin:0px 0px 0px 330px; 
      font-family: Myriad Pro,Normal,strong; 
      font-size: 16px; 
      border:none; 
      background-color:transparent; 
      color:#000; 
      }      
     </style> 


     <script language="JavaScript" src="slider_scripts/slider.js"></script> 
     </head> 

     <body> 
     <form action="#" method="get" name="demoForm" id="slider"> 

     <div id="sliderimpact2_slide2" ontouchmove="calc(),put_zero();"> 

     <input name="sliderValue" type="Text" id="sliderValue140h" onChange="A_SLIDERS[5].f_setValue(this.value)" value="5" size="3" readonly> 

     <script language="JavaScript"> 

    var A_TPLh140h = { 

    'b_vertical' : false, 

    'b_watch': true, 

    'n_controlWidth': 356, 

    'n_controlHeight': 29, 

    'n_sliderWidth': 32, 

    'n_sliderHeight': 33, 

    'n_pathLeft' : -5, 

    'n_pathTop' : -8, 

    'n_pathLength' :340, 

    's_imgControl': 'images/slide5slider.png', 

    's_imgSlider': 'images/Slider Circle 2.png', 

    'n_zIndex': 1 

     } 




     var A_INITh140h = { 

    's_form' : 0, 

    's_name': 'sliderValue140h', 

    'n_minValue' : 0, 

    'n_maxValue' : 100, 

    'n_value' : 0, 

    'n_step' : 5, 

     } 


     new slider(A_INITh140h, A_TPLh140h); 

      </script> 

      </div> 
      <br /> 
      <br /> 

      <div id="sliderimpact2_slide2" ontouchmove="calc(),put_zero();"> 

      <input name="sliderValue" type="Text" id="sliderValue150h" onChange="A_SLIDERS[5].f_setValue(this.value)" value="5" size="3" readonly> 

      <script language="JavaScript"> 

     var A_TPLh150h = { 

    'b_vertical' : false, 

    'b_watch': true, 

    'n_controlWidth': 356, 

    'n_controlHeight': 29, 

    'n_sliderWidth': 32, 

    'n_sliderHeight': 33, 

    'n_pathLeft' : -5, 

    'n_pathTop' : -8, 

    'n_pathLength' :340, 

    's_imgControl': 'images/slide5slider.png', 

    's_imgSlider': 'images/Slider Circle 2.png', 

    'n_zIndex': 1 

     } 



      var A_INITh150h = { 

    's_form' : 0, 

    's_name': 'sliderValue150h', 

    'n_minValue' : 0, 

    'n_maxValue' : 100, 

    'n_value' : 0, 

    'n_step' : 5, 

     } 

     new slider(A_INITh150h, A_TPLh150h); 

      </script> 

      </div> 
      <br /> 
      <br /> 





    <div id="sliderimpact2_slide2" ontouchmove="calc(),put_zero();"> 

    <input name="sliderValue" type="Text" id="sliderValue160h" onChange="A_SLIDERS[5].f_setValue(this.value)" value="5" size="3" readonly> 

    <script language="JavaScript"> 

var A_TPLh160h = { 

    'b_vertical' : false, 

    'b_watch': true, 

    'n_controlWidth': 356, 

    'n_controlHeight': 29, 

    'n_sliderWidth': 32, 

    'n_sliderHeight': 33, 

    'n_pathLeft' : -5, 

    'n_pathTop' : -8, 

    'n_pathLength' :340, 

    's_imgControl': 'images/slide5slider.png', 

    's_imgSlider': 'images/Slider Circle 2.png', 

    'n_zIndex': 1 

    } 



     var A_INITh160h = { 

    's_form' : 0, 

    's_name': 'sliderValue160h', 

    'n_minValue' : 0, 

    'n_maxValue' : 100, 

    'n_value' : 0, 

    'n_step' : 5, 

     } 

     new slider(A_INITh160h, A_TPLh160h); 

      </script> 

      </div> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 

      <img src="images/Show Impact.png" onclick="slidercalsevere();"> 
      <div class="wrap"> 
    <div class="bar"> 
    <div class="percent"> 
    <span style="width: 100%;"></span> 
    </div> 
    </div> 

      <div class="text"> 
    <input type="text" class="input" value="0" id="sliderValue170h"/> 
    </div> 
    </div> 
      </form> 
      </body> 
      </html> 

這裏是單獨的HTML文件只

http://pastebin.com/rsDuEWf3

這裏是腳本音響樂

http://pastebin.com/Sev6yTnb

+0

由於缺乏大寫和標點符號以及大量無關代碼,因此很難理解您的問題。見[問]。 – Antony 2013-04-04 09:00:26

+0

您是否介意在提出問題之前刪除不相關的CSS,標記並將源代碼截斷爲單個文件? – neuront 2013-04-04 09:01:23

+0

「它不工作」是*永遠不是一個適當的問題/錯誤描述。請具體說明您的問題:您希望發生什麼?發生了什麼?你的[調試嘗試]結果是什麼(http://www.netmagazine.com/tutorials/javascript-debugging-beginners)? – 2013-04-04 09:01:28

回答

0

如果要加載的頁面使用的加載功能的window.onload =增加;

相關問題