我有2个需要验证的文本字段。
我要做的是弹出一个警告框,用于合并原因(无论如何),如果没有隐藏,则在警报中为条形码添加验证消息
以下是代码:
<tr><td>
<input type="checkbox" name="createCharge" id="createCharge" onClick="checkBox('Barcode', 'CreateCharge');" value="1"/>
<lable>Charge</label>
</td></tr>
<tr id="Barcode" style="display:none;">
<td>
<label>Barcode</label>
<input type="text" name="Barcode" id="Barcode"/>
</td>
</tr>
<tr>
<td>
<label>Merge:</label>
<input type="text" name="Reason" id="Reason"/>
</td>
</tr>
答案 0 :(得分:2)
你可以这样检查: -
if($(x).is(":visible"))
{
//your element is visible
}
<强> JAVASCRIPT 强>
var display= document.getElementById('x').style.display;
if(display=='block')
{
//do validation here.
}
答案 1 :(得分:1)
if( $('#Barcode').is(':visible') ){
// Perform code here
}
How do I check if an element is hidden in jQuery?
if( $('#Barcode').is(':visible') && $('#Reason').val().length!==0 ){
// Barcode is visible and reason has a value more then 0 chars long
}