链接计数器的问题 [英] Problem with link counter

查看:64
本文介绍了链接计数器的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码我想用作链接计数器,但它不会存储数字也不会增加它。请帮忙。我尽快需要这个。



[HTML]

<! - 开始:JAVASCRIPT for Counter - >



< script type =" text / javascript">

/ *加总1 * /

函数addItem(theCount){

if(parseFloat(document.getElementById(theCount))。 in nerHTML)> 0){

document.getElementById(theCount).innerHTML = parseFloat(document.getElementById(theCount).inner HTML)+ 1;

}

}

/ *只要总数大于0就从总数中删除1

function removeItem(如果(parseFloat(document.getElementById(theCount).in nerHTML)> 0){
.getElementById(theCount).inner HTML)-1;

}

} * /


/ *根据tagToCheck参数将所有项目重置为0

function resetAllItems(tagToCheck){

var numElements = document.getElementsByTagName(theCount)。length;

var i = 0;

while(i< numElements){

document.getElementsByTagName(theCount)[i] .innerHTML = 0;

i ++

}

} * /


/ *将所有项目计数发布到您的ASP页面* /

函数postItems(){

$ count = 0

document.getElementById(''MentalHealthManual'')。valu e = document.getElementById(''MentalHealthManual'')。inne rHTML;

//document.getElementById(''txtHam'').value = document.getElementById(''countHam'')。innerHTML;

//document.getElementById(''txtCola'').value = document.getElementById(''countCola'')。innerHTML;

//document.getElementById(''frmPostItems'')。submit();

}

< / script>


<! - END:JAVASCRIPT for Counter - >

< p>< a href =" http://vaww.st-louis.med.va.gov/training/MH_National_Manual_07_02_08_v2.pdf"的onclick = QUOT;的addItem( MentalHealthManual); return false;">< img src = .. / employee_news / images / BigNew.gif alt ="点击下载项目" />< / A>

< br />< span id =" MentalHealthManual"的onclick = QUOT;的removeItem( MentalHealthManual);"类= QUOT; ITEMCOUNT"> 0℃; /跨度>金枪鱼三明治< / p> [/ HTML]

解决方案

count = 0

document.getElementById(''MentalHealthManual'')。 e = document.getElementById(''MentalHealthManual'')。inne rHTML;

//document.getElementById(''txtHam'').value = document.getElementById(''countHam'')。innerHTML;

//document.getElementById(''txtCola'').value = document.getElementById(''countCola'')。innerHTML;

//document.getElementById(''frmPostItems'')。submit();

}

< / script>


<! - END:JAVASCRIPT for Counter - >

< p>< a href =" http://vaww.st-louis.med.va.gov/training/MH_National_Manual_07_02_08_v2.pdf"的onclick = QUOT;的addItem( MentalHealthManual); return false;">< img src = .. / employee_news / images / BigNew.gif alt ="点击下载项目" />< / A>

< br />< span id =" MentalHealthManual"的onclick = QUOT;的removeItem( MentalHealthManual);"类= QUOT; ITEMCOUNT"> 0℃; /跨度>金枪鱼三明治< / p> [/ HTML]


addItem永远不会递增,因为初始值为0并且您已检查该值是否大于0.删除if条件。


其次,removeItem被注释掉了。


是的我有很多东西被注释掉了我只想增加它并留下它起来。就像一个柜台。但是我有增加的问题,并使其保持其价值。帮助!

I have this code I would like to use as a link counter but it just will not store the number nor increment it. please help. I need this ASAP.



[HTML]
<!-- Start: JAVASCRIPT for Counter -->


<script type="text/javascript">
/* add 1 to the total */
function addItem(theCount){
if(parseFloat(document.getElementById(theCount).in nerHTML) > 0){
document.getElementById(theCount).innerHTML = parseFloat(document.getElementById(theCount).inner HTML) + 1;
}
}
/* removes 1 from total as long as total is above 0
function removeItem(theCount){
if(parseFloat(document.getElementById(theCount).in nerHTML) > 0){
document.getElementById(theCount).innerHTML = parseFloat(document.getElementById(theCount).inner HTML)-1;
}
} */

/* resets all items according the tagToCheck param to 0
function resetAllItems(tagToCheck){
var numElements = document.getElementsByTagName(theCount).length;
var i = 0;
while (i < numElements){
document.getElementsByTagName(theCount)[i].innerHTML = 0;
i++
}
} */

/* post all item counts to your ASP page */
function postItems(){
$count = 0
document.getElementById(''MentalHealthManual'').valu e = document.getElementById(''MentalHealthManual'').inne rHTML;
//document.getElementById(''txtHam'').value = document.getElementById(''countHam'').innerHTML;
//document.getElementById(''txtCola'').value = document.getElementById(''countCola'').innerHTML;
//document.getElementById(''frmPostItems'').submit();
}
</script>

<!-- END: JAVASCRIPT for Counter -->
<p><a href="http://vaww.st-louis.med.va.gov/training/MH_National_Manual_07_02_08_v2.pdf" onclick="addItem(''MentalHealthManual''); return false;"><img src=../employee_news/images/BigNew.gif alt="click to download item" /></a>
<br /><span id="MentalHealthManual" onclick="removeItem(''MentalHealthManual'');" class="itemCount">0</span> Tuna sandwich</p>[/HTML]

解决方案

count = 0
document.getElementById(''MentalHealthManual'').valu e = document.getElementById(''MentalHealthManual'').inne rHTML;
//document.getElementById(''txtHam'').value = document.getElementById(''countHam'').innerHTML;
//document.getElementById(''txtCola'').value = document.getElementById(''countCola'').innerHTML;
//document.getElementById(''frmPostItems'').submit();
}
</script>

<!-- END: JAVASCRIPT for Counter -->
<p><a href="http://vaww.st-louis.med.va.gov/training/MH_National_Manual_07_02_08_v2.pdf" onclick="addItem(''MentalHealthManual''); return false;"><img src=../employee_news/images/BigNew.gif alt="click to download item" /></a>
<br /><span id="MentalHealthManual" onclick="removeItem(''MentalHealthManual'');" class="itemCount">0</span> Tuna sandwich</p>[/HTML]


addItem can never increment because the initial value is 0 and you''ve got a check that the value is greater than 0. Remove the if-condition.

Secondly, removeItem is commented out.


Yes I have many things commented out I just want to increment and for it to stay up. Just as a counter. But I have problems incrementing and making it hold its value. help!


这篇关于链接计数器的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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