跨越onclick与复选框问题 [英] Span onclick with checkbox problem
问题描述
我想使用span来使用''smarter''复选框。当用户按下
文本时,将选中该复选框。但这不能按预期工作。任何
的想法?
< span style =" cursor:pointer;" onclick =" ClickBoxClick(''IsProd'');">
< input type =" checkbox"名称= QUOT; IsProd"值= QUOT 1 QUOT; />
是产品
< / span>
函数ClickBoxClick(obj)
{
if(document.getElementsByTagName)
{
var el = document.getElementById(obj);
if( el.checked){el.checked = false; }
else {el.checked = true; }
}
}
I want to use a ''smarter'' checkbox using span. When a user press the
text the checkbox is checked. But this dos''t work as expected. Any
idea?
<span style="cursor:pointer;" onclick="ClickBoxClick(''IsProd'');">
<input type="checkbox" name="IsProd" value="1" />
Is a Product
</span>
function ClickBoxClick(obj)
{
if(document.getElementsByTagName)
{
var el = document.getElementById(obj);
if(el.checked) { el.checked=false; }
else { el.checked = true; }
}
}
推荐答案
> "协泰" <涂**** @ gmail.com>写道:
> "GTi" <tu****@gmail.com> wrote:
新闻:11 ********************** @ g44g2000cwa.googlegr oups.com ....
我想使用span来使用''smarter''复选框。当用户按下
文本时,选中复选框。但这不能按预期工作。任何想法?
< span style =" cursor:pointer;" onclick =" ClickBoxClick(''IsProd'');">
< input type =" checkbox"名称= QUOT; IsProd"值= QUOT 1 QUOT; />
是产品
< / span>
函数ClickBoxClick(obj)
{
if(document.getElementsByTagName)
{
var el = document.getElementById(obj);
if(el.checked){el.checked = false; }
else {el.checked = true; }
}
}
news:11**********************@g44g2000cwa.googlegr oups.com....
I want to use a ''smarter'' checkbox using span. When a user press the
text the checkbox is checked. But this dos''t work as expected. Any
idea?
<span style="cursor:pointer;" onclick="ClickBoxClick(''IsProd'');">
<input type="checkbox" name="IsProd" value="1" />
Is a Product
</span>
function ClickBoxClick(obj)
{
if(document.getElementsByTagName)
{
var el = document.getElementById(obj);
if(el.checked) { el.checked=false; }
else { el.checked = true; }
}
}
这就是标签的用途。
< input id = QUOT; myBox上"类型= QUOT;复选框"名称= QUOT; IsProd" value =" 1">
< label for =" mybox" style =" cursor:pointer;">是产品< / label>
-
BootNic 2005年12月14日星期三9: 22 AM
我们的地球在后来的日子里堕落了;贿赂和腐败很常见;孩子不再服从父母;世界末日显然正在逼近。
*亚述粘土片2800 BC *
This is what label is for.
<input id="mybox" type="checkbox" name="IsProd" value="1">
<label for="mybox" style="cursor:pointer;">Is a Product</label>
--
BootNic Wednesday, December 14, 2005 9:22 AM
Our earth is degenerate in these latter days; bribery and corruption are common; children no longer obey their parents; and the end of the world is evidently approaching.
*Assyrian clay tablet 2800 B.C.*
感谢:
< label for = QUOT; myBox上" style =" cursor:pointer;">
< input id =" mybox"类型= QUOT;复选框"名称= QUOT; IsProd" value =" 1">
是产品< / label>
但是我还有另外一个问题:
使用表单中的复选框时,如果不检查
,则不会回复结果。这是一个问题。所以我的下一步是扩展这个函数
,如果选中复选框,则隐藏输入字段的值为0或1.
此解决方案无法解决该问题 - 或者?
It shuld be:
<label for="mybox" style="cursor:pointer;">
<input id="mybox" type="checkbox" name="IsProd" value="1">
Is a Product</label>
But then I have another problem:
Using checkboxes in a form dosn''t post back the result when it is not
checked. That is a problem. So my next step was to extend this function
with a hidden input fields with values 0 or 1 if the checkbox.
This solution does not solve that problem - or?
GTi写道:
GTi wrote:
我想使用span来使用''smarter''复选框。当用户按下
文本时,选中复选框。但这不能按预期工作。任何想法?
< span style =" cursor:pointer;" onclick =" ClickBoxClick(''IsProd'');">
< input type =" checkbox"名称= QUOT; IsProd"值= QUOT 1 QUOT; />
^^^^ [1] ^ [2]
[2] IE不支持XHTML。
是产品
< / span>
< input type ="复选框"名称= QUOT; IsProd" ID = QUOT; IsProdID" value =" 1">< label
for =" IsProdID">是产品< / label>
无需编写脚本在这里,最好的是它是
有效HTML 4.01严格。
功能ClickBoxClick(obj)
{
if( document.getElementsByTagName)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ {
var el = document.getElementById(obj );
^^^^^^^^^^^^^^^^^^^^^^^ if(el.checked){el.checked = false; }
else {el.checked = true; }
}
}
I want to use a ''smarter'' checkbox using span. When a user press the
text the checkbox is checked. But this dos''t work as expected. Any
idea?
<span style="cursor:pointer;" onclick="ClickBoxClick(''IsProd'');">
<input type="checkbox" name="IsProd" value="1" /> ^^^^[1] ^[2]
[2] IE does not support XHTML.
Is a Product
</span>
<input type="checkbox" name="IsProd" id="IsProdID" value="1"><label
for="IsProdID">Is a Product</label>
No scripting is needed here at all, and the best of it is that it is
Valid HTML 4.01 Strict.
function ClickBoxClick(obj)
{
if(document.getElementsByTagName) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ {
var el = document.getElementById(obj); ^^^^^^^^^^^^^^^^^^^^^^^ if(el.checked) { el.checked=false; }
else { el.checked = true; }
}
}
您的脚本不起作用,因为名称不是ID。[1]
您对错误的属性进行了不充分的功能测试
并且您的缩进样式允许改进,顺便说一句。
PointedEars
Your script does not work because names are not IDs.[1]
You are insufficiently feature-testing the wrong property
and your indentation style allows for improvement, BTW.
PointedEars
>
这篇关于跨越onclick与复选框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!