0
我试图隐藏表单标签和文本框,默认情况下,并使它们出现时,选择一个选项。我看不出为什么我的代码保持失败。jQuery遍历表单元素
<tr>
<td><label>My Label</label></td>
<td>
<select name="1" id="1">
<option value="2" selected="selected">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="Other">Other</option>
</select>
</td>
<td><label class=".otherHide">Other</label></td>
<td><input class=".otherHide" type="text" name="otherSpec" id="otherSpec" /></td>
</tr>
jQuery(document).ready(function()
{
jQuery('#1').change(function()
{
jQuery('#1 option:selected').each(function()
{
if (jQuery(this).text() == 'Other')
{
jQuery('.otherHide').each(function()
{
jQuery(this).animate({opacity: 0.0}, 2000);
});
}
});
}).change();
});
它目前设置为隐藏表单元素,为什么我测试。
我原本没有使用类,并试图通过它遍历我的手。如果不这样做,我就会上课,最终失败。
为什么jQuery不选择我的元素? >。 <
这个ID实际上并不是数字。我只是用它们来阻止人们关注不相关的信息。现在回想起来,坏主意的xD 我似乎也粘贴旧代码> _> 最后两个TD的应为: <标签类=”。otherHide “>其他 <输入类=” otherHide。 “type =”text“name =”otherSpec“id =”otherSpec“/> – Kane 2009-10-22 05:38:23
你想要class =”otherHide“而不是class =”。otherHide“。该时间段仅用于CSS选择器以表明您正在寻找一个班级。 – Gareth 2009-10-22 05:50:02
...半小时盯着这段代码试图弄清楚为什么jQuery不能很好地播放,并且它变成了HTML> _> 感谢您的帮助;) – Kane 2009-10-22 05:54:58