javascript无法在我的内容页面上工作 [英] javascript wont work on my content page

查看:130
本文介绍了javascript无法在我的内容页面上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是该客户端脚本的新手.我的问题是香港专业教育学院有很多文本框,我希望它们自动计算,但到目前为止没有任何效果.我的脚本有错吗?请帮忙.

I am new on this client side scripting. My problem is ive got a lot of textboxes and i want them to autocalculate but so far nothing works. Is there someting wrong on my script? please help.

function totaltraininghour()
{
var totalhour1=0;
var a1= parseInt(document.getElementById("a1").value);
var b1= parseInt(document.getElementById("b1").value);
var c1= parseInt(document.getElementById("c1").value);
var d1= parseInt(document.getElementById("d1").value);

var totalhour2=0;
var a2= parseInt(document.getElementById("a2").value);
var b2= parseInt(document.getElementById("b2").value);
var c2= parseInt(document.getElementById("c2").value);
var d2= parseInt(document.getElementById("d2").value);

var totalhour3=0;
var a3= parseInt(document.getElementById("a3").value);
var b3= parseInt(document.getElementById("b3").value);
var c3= parseInt(document.getElementById("c3").value);
var d3= parseInt(document.getElementById("d3").value);

var totaltraining=0;

if (a1 >=0)
{
totalhour1 = totalhour1 + a1
}
if (b1>=0)
{
totalhour1 = totalhour1+ b1
}
if (c1>=0)
{
totalhour1 = totalhour1+ c1
}
if (d1>=0)
{
totalhour1 = totalhour1+ d1
}
document.getElementById("txttotalhour1").value = totalhour1

if (a2 >=0)
{
totalhour2 = totalhour2 + a2
}
if (b2>=0)
{
totalhour2 = totalhour2+ b2
}
if (c2>=0)
{
totalhour2 = totalhour2+ c2
}
if (d2>=0)
{
totalhour2 = totalhour2+ d2
}
document.getElementById("txttotalhour2").value = totalhour2

if (a3 >=0)
{
totalhour3 = totalhour2 + a3
}
if (b3>=0)
{
totalhour3 = totalhour2+ b3
}
if (c3>=0)
{
totalhour3 = totalhour2+ c3
}
if (d3>=0)
{
totalhour3 = totalhour2+ d3
}
document.getElementById("txttotalhour3").value = totalhour3

totaltraining = totalhour1 + totalhour2 + totalhour3
document.getElementById("txttotaltraininghours").value = totaltraining
</script>


<asp:TextBox ID="a2" runat="server" Width="100px" onkeyup="totaltraininghour ();"></asp:TextBox>

等等

推荐答案

而不是使用onKeyup,请在Pageload上使用此方法

a2.Attributes.Add("javascript:onkeyup","returun totaltraininghour()")

原因是您使用的是ASP文本框,它是服务器控件,因此您想在此应用客户端脚本:)

问候

Salman
Instead of using onKeyup use this on Pageload

a2.Attributes.Add("javascript: onkeyup","returun totaltraininghour()")

The reason is that you are using asp TextBox,which is a server control and on this you want to apply client side script :)

Regards

Salman


我认为ID有问题,因此请使用客户端ID代替ID.如果您使用的是.net 4.0,请设置属性ClientIdMode ="Static"或使用
I think issue with id so use client id instead of id. If you are using .net 4.0 then set attribute ClientIdMode="Static" OR use
document.getElementById(''<%=a2.ClientID%>'')


这篇关于javascript无法在我的内容页面上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆