2014-02-11 164 views
-1

我有這個javascript和它的工作很好在asp.net ,,,但我嘗試這個腳本在PHP中的相同的例子,但不工作什麼是錯的?將JavaScript轉換爲PHP Javascript

我已經拉布勒包括價值,,我嘗試讓拉布勒價值和隱藏字段插入,

這是我的腳本

 <script type="text/javascript"> 

     function Calculate() { 
      var Txt_Percent = document.getElementById('<%= txt_Percent.ClientID %>'); 
      var Txt_Fix = document.getElementById('<%= txt_Fix.ClientID %>'); 
      if (document.getElementById('<%= rad_Fix.ClientID %>').checked == true) { 
      document.getElementById('txt_Percent').disabled = true; 

      var lblReadCost = document.getElementById('<%= lbl_Read_Cost.ClientID %>'); 

      var lblReadCostValue; 
      var Lab_Read_Net = document.getElementById('<%= lbl_Read_Net.ClientID %>'); 
      var hf_Read_Net = document.getElementById('<%= hf_Read_Net.ClientID %>'); 


      if (navigator.appName == 'Netscape') 
       lblReadCostValue = lblReadCost.textContent; 
      else 
       lblReadCostValue = lblReadCost.innerText; 





      if (navigator.appName == 'Netscape') 
       Lab_Read_Net.textContent = (eval(lblReadCostValue) - eval(Txt_Fix.value)); 
      else 
       Lab_Read_Net.innerText = (eval(lblReadCostValue) - eval(Txt_Fix.value)); 

      hf_Read_Net.value = (eval(lblReadCostValue) - eval(Txt_Fix.value)); 

      if (document.getElementById('<%= txt_Fix.ClientID %>').value == '') { 
       Lab_Read_Net.innerText = (eval(lblReadCostValue)); 
      } 



     } 

     if (document.getElementById('<%= rad_Percent.ClientID %>').checked == false) { 

      Txt_Percent.value = ""; 
     } 


    } 

    </script> 

    <script type="text/ecmascript"> 

    function Calculate1() { 


     var Txt_Fix = document.getElementById('<%= txt_Fix.ClientID %>'); 
     var Txt_Percent = document.getElementById('<%= txt_Percent.ClientID %>'); 

     if (document.getElementById('<%= rad_Percent.ClientID %>').checked == true) { 
      document.getElementById('txt_Fix').disabled = true; 

      var lblReadCost1 = document.getElementById('<%= lbl_Read_Cost.ClientID %>'); 
      var lblReadCostValue1; 

      var Lab_Read_Net = document.getElementById('<%= lbl_Read_Net.ClientID %>'); 
      var hf_Read_Net = document.getElementById('<%= hf_Read_Net.ClientID %>'); 


      if (navigator.appName == 'Netscape') 
       lblReadCostValue1 = lblReadCost1.textContent; 
      else 
       lblReadCostValue1 = lblReadCost1.innerText; 


      if (navigator.appName == 'Netscape') 
       Lab_Read_Net.textContent = (eval(lblReadCostValue1) - eval(Txt_Percent.value)); 




      var x = (eval(lblReadCostValue1) * eval(Txt_Percent.value)/100); 

      Lab_Read_Net.innerText = (eval(lblReadCostValue1) - parseInt(x)); 


      hf_Read_Net.value = (eval(lblReadCostValue1) - parseInt(x)); 

      if (document.getElementById('<%= txt_Percent.ClientID %>').value == '') { 
       Lab_Read_Net.innerText = (eval(lblReadCostValue1)); 
      } 
     } 




     if (document.getElementById('<%= rad_Fix.ClientID %>').checked == false) { 

      Txt_Fix.value = ""; 
     } 



    } 
    </script> 
+1

真正使用你需要一個轉換器?只是改變你的ID –

回答

0

這並不在PHP工作:

<%= txt_Percent.ClientID %> 

因爲你沒有這些對象。輸入字段只是PHP中的靜態HTML。你必須在Javascript中設置你自己在PHP中設置的ID。

0

您需要更改ASP的Response.Write(<%=xxxx %>)爲PHP回聲<?php echo $xxx; ?>

0

這樣做

// ASP 
var Txt_Percent = document.getElementById('<%= txt_Percent.ClientID %>'); 

轉換你的對象到數組然後像

// PHP 
var Txt_Percent = document.getElementById("<?php echo $txt_Percent['ClientID']; ?>");