我有这个javascript,它的工作在asp.net好,但我在php中的同一个例子中尝试这个脚本,但没有工作,哪有错?
我有lable包含值,我尝试获取标签值并将其插入隐藏字段,
这是我的剧本
<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>
答案 0 :(得分:0)
这在PHP中不起作用:
<%= txt_Percent.ClientID %>
因为你没有这些物品。输入字段只是php中的静态HTML。您必须在Javascript中自己设置您在PHP中设置的ID。
答案 1 :(得分:0)
您需要更改php echos <%=xxxx %>
<?php echo $xxx; ?>
)
答案 2 :(得分:0)
执行类似
的操作// ASP
var Txt_Percent = document.getElementById('<%= txt_Percent.ClientID %>');
将对象转换为数组然后使用
// PHP
var Txt_Percent = document.getElementById("<?php echo $txt_Percent['ClientID']; ?>");