反脚本 [英] Counter Script
问题描述
这个简单的脚本点击按钮会向上或向下计数,现在可以修改为
,这样计数就不会低于零?
*** *******谢谢,乔
< form>
< input type = text name = amount size = 4 value =>
< input type = button value =" up"
onClick =" javascript :this.form.amount.value ++;" ;>
< input type = button value =" down"
onClick =" javascript :this.form.amount。值 - ;">
< / form>
This simple script counts up or down with a button click, now can it be
modified so the count won''t go below zero?
********** Thanks, Joe
<form>
<input type=text name=amount size=4 value=>
<input type=button value="up"
onClick="javascript:this.form.amount.value++;">
<input type=button value="down"
onClick="javascript:this.form.amount.value--;">
</form>
推荐答案
Papajo写道:
Papajo wrote:
这个简单的脚本点击按钮可以向上或向下计数,现在可以修改它以便计数不会低于零吗?>谢谢,乔
< form>
< input type = text name = amount size = 4 value =>
< input type = button value =" up
onClick =" javascript : this.form.amount.value ++;">
< input type = button value =" down"
onClick =" javascript :this.form.amount .value - ;">
< / form>
This simple script counts up or down with a button click, now can it be
modified so the count won''t go below zero?
Thanks, Joe
<form>
<input type=text name=amount size=4 value=>
<input type=button value="up"
onClick="javascript:this.form.amount.value++;">
<input type=button value="down"
onClick="javascript:this.form.amount.value--;">
</form>
不需要javascript协议。除非我无法帮助,否则我不愿意使用
内联javascript。
将脚本放在< head>之间标签,你可以像下面的
:
< script type =" text / javascript">
function countUp(obj)
{
obj.form.amount.value ++;
}
函数countDown(obj)
{
amtObj = obj.form.amount;
if(amtObj.value> 1)
{
obj.form.amount.value--;
}
}
< / script>
至于您的表格:
< form>
< input type =" text" name =" amount">
< input type =" button" value =" up" onClick =" countUp(this);">
< input type =" button" value =" down" onClick =" countDown(this);">
< / form>
There is no need for the javascript protocol. I prefer not to do
inline javascript unless I can''t help it.
Place script in between the <head> tags and you can something like the
following:
<script type = "text/javascript">
function countUp(obj)
{
obj.form.amount.value++;
}
function countDown(obj)
{
amtObj = obj.form.amount;
if(amtObj.value > 1)
{
obj.form.amount.value--;
}
}
</script>
As for your form:
<form>
<input type = "text" name = "amount">
<input type = "button" value = "up" onClick = "countUp(this);">
<input type = "button" value = "down" onClick = "countDown(this);">
</form>
Papajo说:
这个简单的脚本点击按钮会向上或向下计数,现在是否可以修改,因此计数不会低于零?
= A0 = A0 = A0 = A0 = A0 = A0 = A0 = A0 = A0 = A0谢谢,乔
< form>
< input type = 3Dtext name = 3Damount size = 3D4 value = 3D> ;
<输入类型= 3D按钮值= 3D" up"
onClick = 3D" javascript :this.form.amount.value ++; ">
< input type = 3Dbutton value = 3D" down"
onClick = 3D" javascript :this.form.amount.value - ;"> ;
< / form>
This simple script counts up or down with a button click, now can it be
modified so the count won''t go below zero?
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Thanks, Joe
<form>
<input type=3Dtext name=3Damount size=3D4 value=3D>
<input type=3Dbutton value=3D"up"
onClick=3D"javascript:this.form.amount.value++; ">
<input type=3Dbutton value=3D"down"
onClick=3D"javascript:this.form.amount.value--;">
</form>
< form>
< input type =" text"名称= QUOT;量QUOT;大小= QUOT; 4英寸value =" 0">
< input type =" button" value =" up"
onClick =" this.form.amount.value ++;">
< input type =" button" value =" down"
onClick =" if(this.form.amount.value>''0'')this.form.a mount.value - ;">
< / form>
<form>
<input type="text" name="amount" size="4" value="0">
<input type="button" value="up"
onClick="this.form.amount.value++;">
<input type="button" value="down"
onClick="if(this.form.amount.value>''0'')this.form.a mount.value--;">
</form>
Lee于2005年30月30日在comp.lang.javascript中写道 :
Lee wrote on 30 sep 2005 in comp.lang.javascript:
Papajo说:
< form>
< input type =" text"名称= QUOT;量QUOT;大小= QUOT; 4英寸value =" 0">
< input type =" button" value =" up"
onClick =" this.form.amount.value ++;">
< input type =" button" value =" down"
onClick =" if(this.form.amount.value>''0'')this.form.a mount.value - ;">
< ; / form>
Papajo said:
<form>
<input type="text" name="amount" size="4" value="0">
<input type="button" value="up"
onClick="this.form.amount.value++;">
<input type="button" value="down"
onClick="if(this.form.amount.value>''0'')this.form.a mount.value--;">
</form>
this.form.amount.value>''0''
括号是不必要的。
当达到0时禁用向下按钮会更好:
====================== ==
< form>
< input type =" text"名称= QUOT;量QUOT;大小= QUOT; 4英寸value =" 2">
< input type =" button" value =" up"
onClick =" this.form.amount.value ++;
document.getElementById(''down'')。disabled = false"> ;
< input type =" button"值= QUOT;向下" id =''down''
onClick =" this.disabled =( - this.form.amount.value == 0);">
< / form>
=========================
ie6测试
-
Evertjan。
荷兰。
(在我的电子邮件地址中用点替换所有十字架)
this.form.amount.value>''0''
the parentheses are unnecessary.
Much better to disable the down button when 0 is reached:
========================
<form>
<input type="text" name="amount" size="4" value="2">
<input type="button" value="up"
onClick="this.form.amount.value++;
document.getElementById(''down'').disabled=false">
<input type="button" value="down" id=''down''
onClick="this.disabled=(--this.form.amount.value==0);">
</form>
=========================
ie6 tested
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
这篇关于反脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!