2013-04-12 115 views
0

到目前爲止我沒有成功的第一個輸入按鈕啓動錶轉換功能。目前我正在測試功能。我已盡力通過一些教科書和在線搜索來查看格式,我認爲我的語法正確。尋找建議,爲什麼tableShifts()沒有從Calculate Shifts按鈕引用。謝謝。onclick沒有激活指定的功能

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<HTML> 
<HEAD> 
<TITLE>Couch Shifts</TITLE> 
<script type="text/javascript">  

    function openWindow() 
     { 
      window.open('','',"toolbar=no, menubar=no, directories=no, status=no, resizable=no, scrollbars=no, height=120,width=510"); 
     } 

    function patientPosition() 
     { 
      var x = 1; 
      var Position = document.getElementbyId("Position").value; 
      switch (patPosition){ 
      case "HFS": 
       x = x*1   
      case "HFP": 
       x = x*-1    
      case "FFS": 
       x = x*1   
      case "FFP": 
       x = x*-1   
      } 
     } 

    function tableShifts() 
     { 
      alert("test"); 
     } 

    function parameters() 
     {   
      var curVert = Number(document.getElementById("curVert").value), 
      var curLat = Number(document.getElementById("curLat").value), 
      var curLong = Number(document.getElementById("curLong").value), 

      var pinVert = Number(document.getElementById("curVert").value), 
      var pinLat = Number(document.getElementById("curVert").value), 
      var pinLong = Number(document.getElementById("curVert").value); 

      document.getElementById("gotoVert").value = curVert - pinVert; 
      document.getElementById("gotoLat").value = curLat + pinLat; 
      document.getElementById("gotolong").value = curLong - pinLong; 
      } 

</script> 
    </HEAD> 
    <BODY> 
<select Id="Position"> 
    <option value="HFS">Head First Supine</option> 
    <option value="HFP">Head First Prone</option> 
    <option value="FFS">Feet First Supine</option> 
    <option value="FFP">Feet First Prone</option> 
</select><br><br> 
<div style="margin-bottom: 120px;"> 
<style> 
    label { float: left; width: 35px; } 
    #column1{ float: left; position: relative; z-index: 0; width: 150px;} 
    #column2{ float: left; position: relative; z-index: 2; width: 150px;} 
    #column3{ float: left; position: relative; z-index: 1; width: 125px;} 
    #button { position: absolute; } 
</style> 
<div id="column1">Current Position</br></br> 
    <label for="Vert">Vert:</label> 
    <input type="text", id="curVert" size="10" value="" /></br> 
    <label for="Lat">Lat:</label> 
    <input type="text" size="10", id="curLat" value="" /></br> 
    <label for="Long">Long:</label> 
    <input type="text" size="10", id="curLong" value="" /> 
</div> 

<div id="column2">Pinnicle Shifts<br><br> 
    <label for="Vert">Vert:</label> 
    <input type="text", id="pinVert" size="10" value="" /></br> 
    <label for="Lat">Lat:</label> 
    <input type="text", id="pinLat" size="10" value="" /></br> 
    <label for="Long">Long:</label> 
    <input type="text", id="pinLong" size="10" value="" />  
</div> 

<div id="column3">Calculated Shifts</br></br> 
    <label for="Vert">Vert:</label> 
    <input type="text", id="gotoVert" size="10" value="" readonly="readonly" style="background-color:#D8D8D8 ;"/></br> 
    <label for="Lat">Lat:</label> 
    <input type="text", id="gotoLat" size="10" value="" readonly="readonly" style="background-color:#D8D8D8 ;"/></br> 
    <label for="Long">Long:</label> 
    <input type="text", id="gotoLong" size="10" value="" readonly="readonly" style="background-color:#D8D8D8 ;"/>  
</div><br /> 
</div> 

<div id="button"> 
    <input type = "button" style="margin-top: 10px;" value="Calculate Shifts" onclick="tableShifts();" /> 
    <input type = "button" style="margin-top: 10px;" value="Reset" onclick=""/> 
</div> 
</BODY> 
</HTML> 
+0

在你標記了很多錯誤... – Givi

+0

道歉,向新的HTML和JavaScript。我可以問問您是否有可供審查的資源來嘗試和改進? – TargetofGravity

+0

我在你的標記中看到的唯一一件事是不一致的(和一個錯誤的)使用'br'標籤(我可能錯過了一些艱難的東西)。使用[W3C標記驗證服務](http://validator.w3.org)進行html標記驗證,使用[JSLint](http://www.jslint.com)進行EcmaScript驗證(如javascript)驗證。爲了學習,我強烈建議['Crockford on Javascript'。完整的播放列表。](http://www.youtube.com/playlist?list=PL7664379246A246CB) – GitaarLAB

回答

0

在功能tableShiftsss您有:

var gotoVert.value = curVert - pinVert; 
    var gotoLat.value = curLat + pinLat; 
    var gotolong.value = curLong - pinLong; 

也就是說沒有有效的EcmaScript方言(比如JavaScript)。

你可能想改變這種狀況到:

function tableShifts(){   
    var curVert = Number(document.getElementById("curVert").value), 
     curLat = Number(document.getElementById("curLat").value), 
     curLong = Number(document.getElementById("curLong").value), 

     pinVert = Number(document.getElementById("curVert").value), 
     pinLat = Number(document.getElementById("curVert").value), 
     pinLong = Number(document.getElementById("curVert").value); 

    document.getElementById("gotoVert").value = curVert - pinVert; 
    document.getElementById("gotoLat").value = curLat + pinLat; 
    document.getElementById("gotolong").value = curLong - pinLong; 
} 

祝你好運!

+0

謝謝!不知不覺擡起頭來,知道了數字()所做的是什麼,非常恰當。 – TargetofGravity

+0

謝謝大家。這些建議會導致一些問題,其中一個是數字方法的介紹,另一個是用於調試的安裝螢火蟲。我很感激幫助 – TargetofGravity

0

裏面你tableShiftsss(),你說:

var gotoVert.value 

雖然它應該是:

document.getElementById("gotoVert").value 

這適用於所有這三個語句。

此外,值函數返回的字符串不是int,所以您不能只添加結果。實際上,您將需要轉換爲int,像這樣:

var curVert = parseInt(document.getElementById("curVert").value); 

你可能有其他的語法錯誤,但最多也就是您在使用瀏覽器的JavaScript控制檯來調試。

0

試試這個

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
     <HTML> 
     <HEAD> 
     <TITLE>Couch Shifts</TITLE> 
     <script type="text/javascript">  



      function tableShifts() 
       { 
        alert("test"); 
       } 

     function openWindow() 
       { 
        window.open('','',"toolbar=no, menubar=no, directories=no, status=no, resizable=no, scrollbars=no, height=120,width=510"); 
       } 

      function patientPosition() 
       { 
        var x = 1; 
        var Position = document.getElementbyId("Position").value; 
        switch (patPosition){ 
        case "HFS": 
         x = x*1   
        case "HFP": 
         x = x*-1    
        case "FFS": 
         x = x*1   
        case "FFP": 
         x = x*-1   
        } 
       } 

      function parameters() 
       {   
        var curVert = Number(document.getElementById("curVert").value); 
        var curLat = Number(document.getElementById("curLat").value); 
        var curLong = Number(document.getElementById("curLong").value); 

        var pinVert = Number(document.getElementById("curVert").value); 
        var pinLat = Number(document.getElementById("curVert").value); 
        var pinLong = Number(document.getElementById("curVert").value); 

        document.getElementById("gotoVert").value = curVert - pinVert; 
        document.getElementById("gotoLat").value = curLat + pinLat; 
        document.getElementById("gotolong").value = curLong - pinLong; 
        } 

     </script> 
      </HEAD> 
      <BODY> 
     <select Id="Position"> 
      <option value="HFS">Head First Supine</option> 
      <option value="HFP">Head First Prone</option> 
      <option value="FFS">Feet First Supine</option> 
      <option value="FFP">Feet First Prone</option> 
     </select><br><br> 
     <div style="margin-bottom: 120px;"> 
     <style> 
      label { float: left; width: 35px; } 
      #column1{ float: left; position: relative; z-index: 0; width: 150px;} 
      #column2{ float: left; position: relative; z-index: 2; width: 150px;} 
      #column3{ float: left; position: relative; z-index: 1; width: 125px;} 
      #button { position: absolute; } 
     </style> 
     <div id="column1">Current Position</br></br> 
      <label for="Vert">Vert:</label> 
      <input type="text" id="curVert" size="10" value="" /></br> 
      <label for="Lat">Lat:</label> 
      <input type="text" size="10" id="curLat" value="" /></br> 
      <label for="Long">Long:</label> 
      <input type="text" size="10" id="curLong" value="" /> 
     </div> 

     <div id="column2">Pinnicle Shifts<br><br> 
      <label for="Vert">Vert:</label> 
      <input type="text", id="pinVert" size="10" value="" /></br> 
      <label for="Lat">Lat:</label> 
      <input type="text", id="pinLat" size="10" value="" /></br> 
      <label for="Long">Long:</label> 
      <input type="text", id="pinLong" size="10" value="" />  
     </div> 

     <div id="column3">Calculated Shifts</br></br> 
      <label for="Vert">Vert:</label> 
      <input type="text", id="gotoVert" size="10" value="" readonly="readonly" style="background-color:#D8D8D8 ;"/></br> 
      <label for="Lat">Lat:</label> 
      <input type="text", id="gotoLat" size="10" value="" readonly="readonly" style="background-color:#D8D8D8 ;"/></br> 
      <label for="Long">Long:</label> 
      <input type="text", id="gotoLong" size="10" value="" readonly="readonly" style="background-color:#D8D8D8 ;"/>  
     </div><br /> 
     </div> 

     <div id="button"> 
      <input type = "button" style="margin-top: 10px;" value="Calculate Shifts" onclick="tableShifts();" /> 
      <input type = "button" style="margin-top: 10px;" value="Reset" onclick=""/> 
     </div> 
     </BODY> 
     </HTML>