【问题标题】:Bootstrap validate only if field contain valueBootstrap 仅在字段包含值时验证
【发布时间】:2025-12-10 01:40:01
【问题描述】:

Bootstrap 仅在字段包含值时验证

我只想在以下情况下使用我的引导验证器

我在下面得到了这个使用引导验证器的代码

<tr>
<td><b>1</b></td>
<td>
<select class="form-control" name="DaySelection1">
<option value="">Select</option>
<option value="wed">Wed</option>
<option value="thu">Thu</option>
<option value="fri">Friday</option>
</select>
</td>

<td class="form-group">
<input type="text" class="form-control" name="digits1"
                required
                min="000"
                data-bv-greaterthan-inclusive="true"
                data-bv-greaterthan-message="The input must be greater than or equal to 0"

                max="999"
                data-bv-lessthan-inclusive="false"
                data-bv-lessthan-message="The input must be less than or equal to 999" />
</td>
<td class="form-group"><input type="number" data-bv-digits-message="true" class="form-control" name="big1" id="name1" size="6"></td>
<td><input type="number" class="form-control" name="small1" size="6"></td>
</tr>

我只想在该行上运行我的验证

select class by the name "DaySelection" value is not "" 

The name of each input is goes by e.g "digits$i", "big$i", "small$i"

其中$i是一个整数

1 to 10

识别输入类型的每一行

如何更改我的引导代码。

因为目前我有一个 for 循环打印出相同的字段,那些未填写的字段也完成了此验证,我只想验证获得 DaySelection 值的行

【问题讨论】:

    标签: php jquery twitter-bootstrap validation


    【解决方案1】:

    我用

    data-bv-threshold="1" 
    

    解决我的问题。

    【讨论】: