将asp Javascript转换为php Javascript
我有这个javascript,它在asp.net中工作得很好,但是我在php的同一个例子中尝试了这个脚本,但是没有工作。有什么错 我有标签包含值,我尝试获取标签值并将其插入隐藏字段 这是我的剧本将asp Javascript转换为php Javascript,javascript,php,Javascript,Php,我有这个javascript,它在asp.net中工作得很好,但是我在php的同一个例子中尝试了这个脚本,但是没有工作。有什么错 我有标签包含值,我尝试获取标签值并将其插入隐藏字段 这是我的剧本 <script type="text/javascript"> function Calculate() { var Txt_Percent = document.getElementById('<%= txt_Percent.Client
<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>
函数计算(){
var Txt_Percent=document.getElementById(“”);
var Txt_Fix=document.getElementById(“”);
if(document.getElementById(“”).checked==true){
document.getElementById('txt_Percent')。disabled=true;
var lblReadCost=document.getElementById(“”);
var lblReadCostValue;
var Lab_Read_Net=document.getElementById(“”);
var hf_Read_Net=document.getElementById(“”);
如果(navigator.appName=='Netscape')
lblReadCostValue=lblReadCost.textContent;
其他的
lblReadCostValue=lblReadCost.innerText;
如果(navigator.appName=='Netscape')
Lab_Read_Net.textContent=(eval(lblReadCostValue)-eval(Txt_Fix.value));
其他的
Lab_Read_Net.innerText=(eval(lblReadCostValue)-eval(Txt_Fix.value));
hf_Read_Net.value=(eval(lblReadCostValue)-eval(Txt_Fix.value));
if(document.getElementById(“”).value==“”){
Lab_Read_Net.innerText=(eval(lblReadCostValue));
}
}
if(document.getElementById(“”).checked==false){
Txt_Percent.value=“”;
}
}
函数Calculate1(){
var Txt_Fix=document.getElementById(“”);
var Txt_Percent=document.getElementById(“”);
if(document.getElementById(“”).checked==true){
document.getElementById('txt_Fix')。disabled=true;
var lblReadCost1=document.getElementById(“”);
var lblReadCostValue1;
var Lab_Read_Net=document.getElementById(“”);
var hf_Read_Net=document.getElementById(“”);
如果(navigator.appName=='Netscape')
lblReadCostValue1=lblReadCost1.textContent;
其他的
lblReadCostValue1=lblReadCost1.innerText;
如果(navigator.appName=='Netscape')
Lab_Read_Net.textContent=(eval(lblReadCostValue1)-eval(Txt_Percent.value));
var x=(评估(lblReadCostValue1)*评估(Txt_百分比值)/100);
Lab_Read_Net.innerText=(eval(lblReadCostValue1)-parseInt(x));
hf_Read_Net.value=(eval(lblReadCostValue1)-parseInt(x));
if(document.getElementById(“”).value==“”){
Lab_Read_Net.innerText=(eval(lblReadCostValue1));
}
}
if(document.getElementById(“”).checked==false){
Txt_Fix.value=“”;
}
}
这在PHP中不起作用:
<%= txt_Percent.ClientID %>
因为你没有这些东西。输入字段在php中只是静态HTML。您必须自己在Javascript中设置在PHP中设置的ID。您需要更改PHP echos的asp response.write(
)执行以下操作
// ASP
var Txt_Percent = document.getElementById('<%= txt_Percent.ClientID %>');
//ASP
var Txt_Percent=document.getElementById(“”);
将对象转换为数组,然后使用
// PHP
var Txt_Percent = document.getElementById("<?php echo $txt_Percent['ClientID']; ?>");
//PHP
var Txt_Percent=document.getElementById(“”);
您真的需要转换器吗?只要换一下身份证就行了