默认情况下,我试图隐藏表单标签和文本框,并在选择选项时显示它们。我不明白为什么我的代码一直失败。
<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 不选择我的元素?>.<