盒子 - 我也不小心在alt.html发布了这个盒子 [英] tic the boxes - I also accidentally posted this one in alt.html

查看:63
本文介绍了盒子 - 我也不小心在alt.html发布了这个盒子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大师


我很抱歉问了这么多问题,但遗憾的是,你只是这样一个很棒的知识来源我不能帮助自己,但问了很多。一天

天,我希望能够回答其他人的问题。


我们走了,我有以下功能(我做了它我自己......!)


函数tic(form,a,z){

for(f = a; z; f ++){

if(form [f] .type ==" checkbox"){

form [f] .checked = true;

}

}

}


它应该勾选一系列的复选框(例如1-10或11-30),我想要

使用a和z来识别范围。


我使用以下方法调用该函数:


< LABEL FOR =" 0">

< INPUT TYPE ="复选框" VALUE =" 0" NAME =" 0" CLASS =" ix"

ONCLICK =" tic(this.form,0,1);">

New Zealand Wide< / LABEL>


但是,即使范围从0到1,它也会勾选

表格中的所有方框。其次,有谁知道如何制作反向功能?我可以

添加第四个变量来指示当前的复选框是真的还是

false然后在函数中使用它?


我希望一切都有意义


再次感谢您的帮助


- Nicolaas

Hi Gurus

I am sorry to ask so many questions, but unfortunately, you are just such an
awesome source of knowledge that I can not help myself but ask lots. One
day, I hope to be able to answer other people''s questions.

Here we go, I have the following function (I made it myself ...!)

function tic(form,a,z){
for(f=a;z;f++){
if(form[f].type=="checkbox"){
form[f].checked=true;
}
}
}

It is supposed to tick a range of tickboxes (e.g. 1-10 or 11-30), I want to
use a and z to identify the range.

I use the following to call the function:

<LABEL FOR="0">
<INPUT TYPE="checkbox" VALUE="0" NAME="0" CLASS="ix"
ONCLICK="tic(this.form,0,1);">
New Zealand Wide</LABEL>

However, even with a range from 0 to 1, it will tick all the boxes in the
form. Secondly, does anyone know how to make the reverse function? Can I
add a fourth variable that indicates whether the current tickbox is true or
false and then use this in the function?

I hope it all makes sense

Thank you once more for all your help

- Nicolaas

推荐答案

2004年11月24日星期三10:45:31 +1300,WindAndWaves< ac **** @ ngaru.com>写道:


[snip]
On Wed, 24 Nov 2004 10:45:31 +1300, WindAndWaves <ac****@ngaru.com> wrote:

[snip]
function tic(form,a,z){
for(f = a; z ; f ++){


你描述的第一个问题是由条件(中)引起的

表达式:它不是比较。只要z非零,循环就会持续执行
。这个函数退出的唯一原因是

,因为最终你试图索引一个不存在的元素并尝试访问一个属性,这将导致错误。

if(form [f] .type ==" checkbox"){
form [f] .checked = true;
}
}
}


这解决了这两个问题:


函数setRange(形式,开始,结束,值){

for( var i = start,e = form.elements; i< = end; ++ i){

if(''checkbox''== e [i] .type){

e [i] .checked = value;

}

}

}


[snip]

< LABEL FOR =" 0">
< INPUT TYPE ="复选框" VALUE =" 0" NAME =" 0" CLASS =" ix"
function tic(form,a,z){
for(f=a;z;f++){
The first problem you describe is caused by the condition (middle)
expression: it''s not a comparison. As long as z is non-zero, the loop will
constantly execute. The only reason why this function would exit is
because eventually you attempt to index a nonexistent element and try an
access a property, which will cause an error.
if(form[f].type=="checkbox"){
form[f].checked=true;
}
}
}
This solves both problems:

function setRange(form, start, end, value) {
for(var i = start, e = form.elements; i <= end; ++i) {
if(''checkbox'' == e[i].type) {
e[i].checked = value;
}
}
}

[snip]
<LABEL FOR="0">
<INPUT TYPE="checkbox" VALUE="0" NAME="0" CLASS="ix"




for属性必须与id匹配,而不是名称,并且id无法启动

带有数字。另外,我不会用数字来命名表单控件。它可能会因序数而干扰索引控制。


[snip]


希望有所帮助,

迈克


-

Michael Winter

替换.invalid与.uk通过电子邮件回复。



The for attribute must match an id, not a name, and an id cannot start
with a number. Also, I wouldn''t name a form control with a number. It
might interfere with indexing controls by ordinal.

[snip]

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.




" Michael Winter" < M ****** @ blueyonder.co.invalid>。在消息中写道

news:opshxuyb06x13kvk @ atlantis ...

"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opshxuyb06x13kvk@atlantis...
2004年11月24日星期三10:45:31 +1300,WindAndWaves< ac **** @ ngaru.com>写道:

[snip]
On Wed, 24 Nov 2004 10:45:31 +1300, WindAndWaves <ac****@ngaru.com> wrote:

[snip]
function tic(form,a,z){
for(f = a; z; f ++){
function tic(form,a,z){
for(f=a;z;f++){



你描述的第一个问题是由条件(中)
表达引起的:它不是比较。只要z非零,循环就会不断执行。此函数退出的唯一原因是
因为最终您尝试索引不存在的元素并尝试访问属性,这将导致错误。



The first problem you describe is caused by the condition (middle)
expression: it''s not a comparison. As long as z is non-zero, the loop will
constantly execute. The only reason why this function would exit is
because eventually you attempt to index a nonexistent element and try an
access a property, which will cause an error.

if(form [f] .type ==" checkbox"){
form [f] .checked = true;
}
}
}
if(form[f].type=="checkbox"){
form[f].checked=true;
}
}
}

<这解决了这两个问题:

函数setRange(形式,开始,结束,值){
for(var i = start,e = form.elements; i < = end; ++ i){
if(''checkbox''== e [i] .type){
e [i] .checked = value;
}
}

[snip]



This solves both problems:

function setRange(form, start, end, value) {
for(var i = start, e = form.elements; i <= end; ++i) {
if(''checkbox'' == e[i].type) {
e[i].checked = value;
}
}
}

[snip]

< LABEL FOR =" 0">
< INPUT TYPE ="复选框" VALUE =" 0" NAME =" 0" CLASS =" ix"
<LABEL FOR="0">
<INPUT TYPE="checkbox" VALUE="0" NAME="0" CLASS="ix"



for属性必须与id匹配,而不是名称,并且id无法以数字开头。另外,我不会用数字来命名表单控件。它可能会因序数而干扰索引控制。

[snip]

希望有所帮助,
迈克

- -
Michael Winter
替换.invalid与.uk通过电子邮件回复。



The for attribute must match an id, not a name, and an id cannot start
with a number. Also, I wouldn''t name a form control with a number. It
might interfere with indexing controls by ordinal.

[snip]

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.




这绝对有效!我唯一想知道的是我如何传递调用该​​函数的复选框的

值(即如果用户勾选新的

西兰宽盒子然后所有区域将被勾选,反之亦然)


谢谢 - 你是一个传奇(如最近的帖子中所述)。

- Nicolaas



That definitely works! The only thing I was wondering is how I pass the
value of the tickbox that calls the function (i.e. if the user ticks the new
Zealand wide box then all the regions will be ticked and vice versa)

Thank you - you are a legend (as noted in a recent post).
- Nicolaas




" WindAndWaves" <交流**** @ ngaru.com>在消息中写道

新闻:%k ****************** @ news.xtra.co.nz ...

"WindAndWaves" <ac****@ngaru.com> wrote in message
news:%k******************@news.xtra.co.nz...
值(即如果用户勾选
新西兰宽框,则所有区域将被勾选,反之亦然)
That definitely works! The only thing I was wondering is how I pass the
value of the tickbox that calls the function (i.e. if the user ticks the new Zealand wide box then all the regions will be ticked and vice versa)



[...]


我以为我这样解决了....


函数tic(形式,开始,结束,值){

for(var i = start,e = form.elements; i< = end; ++ i){

if(''checkbox''== e [i] .type){

e [i] .checked =!e [start] .value;

}

}

}


但它似乎不起作用,任何提示???


TIA


-Nicolaas


[ ... ]

I thought I solved it like this ....

function tic(form, start, end, value) {
for(var i = start, e = form.elements; i <= end; ++i) {
if(''checkbox'' == e[i].type) {
e[i].checked = !e[start].value;
}
}
}

but it does not seem to work, any hints???

TIA

-Nicolaas


这篇关于盒子 - 我也不小心在alt.html发布了这个盒子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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