0

默认情况下,我试图隐藏表单标签和文本框,并在选择选项时显示它们。我不明白为什么我的代码一直失败。

<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 不选择我的元素?>.<

4

1 回答 1

1

值得注意的是HTML 4.01 规范

IDNAME标记必须以字母 ([A-Za-z]) 开头,后跟任意数量的字母、数字 ([0-9])、连字符 ("-")、下划线 ("_") , 冒号 (":") 和句点 (".")。

除此之外,otherHide您的 HTML 中没有具有类的元素。

于 2009-10-22T05:29:52.510 回答