显示输入onfocus旁边的信息

时间:2013-05-24 07:57:06

标签: javascript jquery html css

你好我有一个输入字段很少的表单,一旦用户输入文本字段,我想显示一些与特定字段相关的信息。到目前为止,我设法做到了这一点:

 <tr>
 <td>Name&nbsp;</td>
 <td width="162"><input name="txtname" type="text" id="txtname"  /></td>
 <td width="333"><span class="style1"><br/>Enter Your Name, Preferably as per your PAN Card</span></td>
 </tr>
 <tr>
 <td>Father Name&nbsp;</td>
 <td>&nbsp;<input name="txtfname" type="text" id="txtfname"  /></td>
 <td><span>Enter Your Father Name Preferably as per your PAN Card</span></td>
 </tr>
      <tr>
        <td>PAN&nbsp;</td>
        <td>&nbsp;<input name="txtpan" type="text" id="txtpan" onblur="checkPAN()" maxlength="10"  /></td>
        <td>Enter Your PAN No. carefully</td>
      </tr>
      <tr>
        <td>Mobile Number&nbsp;</td>
        <td>&nbsp;<input name="txtmb" type="text" id="txtmb" maxlength="10"  /></td>
        <td>Enter your Mobile No. we will be in touch with you with this No In case of any further details</td>
      </tr>
      <tr>
        <td>Confirm Mobile Number&nbsp;</td>
        <td>&nbsp;<input name="txtmbcnfrm" type="text" id="txtmbcnfrm" maxlength="10"  /></td>
        <td>Reenter your Mobile No.</td>
      </tr>
      <tr>
        <td>Email Id&nbsp;</td>
        <td>&nbsp;<input name="txtemail" type="text" id="txtemail" onchange="emailval()"  /></td>
        <td>Enter your Valid email ID to which you need to receive    Acknowledgement,   </td>
      </tr>

应该隐藏文本字段旁边的所有信息,但是当onFocus应该显示特定信息时,我可以使用jquery执行此操作,但我很困惑如何到达那里。

1 个答案:

答案 0 :(得分:6)

$('input').parent().next().hide();
$('input').on('focus', function () {
    $(this).parent().next().show();
});
$('input').on('blur', function () {
    $(this).parent().next().hide();
});

这是FIDDLE