jQuery表单验证问题,其他框可见时 [英] jQuery form validation issue, other box when visible
问题描述
我有下面的其他框。我想验证该框,只有当它可见时它才不是空白。对于什么应该是直截了当我遇到了麻烦。任何帮助非常感谢。谢谢
I have the below 'other' box. I want to validate the box so its not blank only when it is visible. For what should be straightforward I am having trouble. Any help much appreciated. Thanks
else if($('#myBox_' + id + ':visible')) { if(!blank('otherprodtypebox[<xsl:value-of select="@id"/>]')){alert("Please enter a valid other option");return false;} }
<script type="text/javascript">
function myOtherBox(e, id) {
if (e.value == 'otherprodtype')
{
$('#myBox_' + id).show();
}
else
{
$('#myBox_' + id).hide();
}
}
</script>
<tr style="display:none;">
<xsl:attribute name="id">myBox_<xsl:value-of select="@id"/></xsl:attribute>
<td class="Label">Other</td>
<td>
<input class="amdInputText" type="text" id="otherprodtypebox" value="">
<xsl:attribute name="value"><xsl:value-of select="otherprodtypebox"></xsl:value-of></xsl:attribute>
</input>
</td>
</tr>
编辑:
我几乎拥有它现在工作:
I nearly have it working now:
else if($('#myBox_<xsl:value-of select="@id"/>').is(':visible')) { if(!blank('otherprodtypebox[<xsl:value-of select="@id"/>]')){alert("Please enter a valid other option");return false;} }
确定所以这似乎只检查框是否可见时验证如果它是空的,则会抛出警报,但由于某些奇怪的原因,当我填写框时,它不会按预期抛出警报,但不会让我继续并且没有错误消息
ok so this seems to only check validation when box is visible and throws up the alert if its empty but then for some strange reason when i fill in the box it doesn't throw up the alert as expected but wont let me proceed and no error messages
推荐答案
用 $替换
解决问题 $('#myBox_'+ id +':visible')
'#myBox_'+ id).is(':visible')
replacing $('#myBox_' + id + ':visible')
with $('#myBox_' + id).is(':visible')
fixes the problem
这篇关于jQuery表单验证问题,其他框可见时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!