【发布时间】:2011-10-08 17:35:57
【问题描述】:
为什么 jQuery 中 php 表单输入数组的行为很有趣?
有什么办法可以克服吗?
嗨,我写了这段代码,它可以工作.. 更新 21 个单选输入的形式,以强调选中单选旁边的标签。
*视觉上 - 不像在 html 标签中
$(function()
{
for(count = 0;count<21;count++)
{
result = $("input:radio[name=choice"+count+"]:checked").val();
$("input[name=\"choice"+count+"\"][ value=\""+ result +"\"]").attr("class", "magic");
$("div.radio:has(input.magic)").attr("class", "radio spell");
}
$("input").click(function()
{
$("div.radio:has(input.magic)").attr("class", "radio");
$("input.magic").removeAttr("class", "magic");
var count = 0;
var result = 0;
for(count = 0;count<21;count++)
{
result = $("input:radio[name=choice"+count+"]:checked").val();
$("input[name=\"choice"+count+"\"][ value=\""+ result +"\"]").attr("class", "magic");
$("div.radio:has(input.magic)").attr("class", "radio spell");
}
});
});
这是css
input[type="radio"] {
height: 20px;
}
input[type="radio"] + label {
color: #777;
font-weight:100;
letter-spacing: 1px;
}
input[type="radio"].magic + label {
color: black;
font-style: italic;
/*text-decoration:underline;*/
font-weight: 600;
letter-spacing: 0px;
text-align: center;
display:inline-block;
width: 80px;
}
div.radio.spell {
border: outset white 2px;
}
现在使用的无线电名称是choice0 -choice20 它工作正常。
在此之前我使用了选择[0] - 选择[20] 它根本不起作用。 它的行为很奇怪。
jQuery 代码类似于: 结果 = $("input:radio[name=choice["+count+"]]:checked").val(); ...
我想知道,有什么办法吗?
感谢您提供宝贵意见。
【问题讨论】:
-
工作得很好,自己看看jsfiddle.net/MqQh4
-
做这个选择[20] 你又创建了一个数组,你有没有相应地改变你的 ajax,所以它可以处理这个?
标签: php jquery html arrays forms