在Submit上添加class to selectpicker下拉列表

时间:2016-10-03 02:32:38

标签: jquery validation bootstrap-selectpicker

我尝试在此处下拉列表中添加/删除的课程(input-validation-error)添加到<div class="btn-group bootstrap-select required"时,&#34;继续&#34;单击,仅在下拉选择更改时单击。

input-validation-error班级将在&#34;继续&#34;单击,向用户显示他们需要从下拉列表中进行选择。我使用selectpicker来重新设置Bootstrap下拉列表,并使用jquery validate进行验证。

.input-validation-error button {
    border: 1px solid red;
}

<select name="country" id="country" class="required selectpicker">
      <option value="">Select Country</option>
      <option value="Afghanistan">Afghanistan</option>
      [...]
</select>


$(function () {
  $('select[name^="country"]').change(function () {
    var selValue = $(this).val();
    $("#form-jsvalidate").validate().element(this);
    if (selValue.length > 0) {
      $(this).next('div').removeClass("input-validation-error");
    }
    else {
      $(this).next('div').addClass("input-validation-error");
    }
  });
});

我认为它应该是$('.btn-submit-val').on('click', function() { var selValue = $('select[name^="country"]').val();之类的东西,但显然不是因为那样,我尝试的其他一切都不起作用。非常感谢正确方向的任何一点。

https://jsfiddle.net/DTcHh/25795/

编辑:任何人?

1 个答案:

答案 0 :(得分:0)

我不明白你想把错误信息放在哪里,但我在你的小提琴中做了一些编辑,现在检查它是否有帮助。

请更清楚地说明您要将错误消息放在何处。

Function RedFinder(MyCellColumn As Integer, MyOffset As Integer, MonthCheck As Integer, YearCheck As Integer)
    Application.Volatile
'    Dim MyCellRow As Integer     'row I want to select
    Dim MyMoneyValue As Variant 'Single holds a decimal variable
    Dim MyAnswerString As String
'    Sheets("Sheet1").Activate  'activate sheet1 at cell script runs on
'    MyCellRow = 115              'set variable MyCellRow to row 1
    MyMoneyValue = CDec("0.0")


'    ActiveSheet.Cells(MyCellRow, MyCellColumn).Select    'select active cell based on input vars
    For MyCellRow = 2 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row    'for loop used to go through all cells
        If IsDate(ActiveSheet.Cells(MyCellRow, MyCellColumn)) Then    'checks if cell is a date
            If Month(ActiveSheet.Cells(MyCellRow, MyCellColumn)) = MonthCheck And Year(ActiveSheet.Cells(MyCellRow, MyCellColumn)) = YearCheck Then    'checks if month and date match
                If IsNumeric(ActiveSheet.Cells(MyCellRow, MyCellColumn).Offset(0, MyOffset)) Then    'checks if corresponding column is a number
                    If ActiveSheet.Cells(MyCellRow, MyCellColumn).Offset(0, MyOffset).Font.Color = 255 Then    'checks if cell text color is red, 255 is the number Font.Color returns for RGB Red (255,0,0)
                        MyMoneyValue = MyMoneyValue + ActiveSheet.Cells(MyCellRow, MyCellColumn).Offset(0, MyOffset)    'adds cell value to MyMoneyValue
'                       MyAnswerString = MyMoneyValue
'                       MyCellRow = MyCellRow + 1
'                   Else
'                       MyCellRow = MyCellRow + 1
                    End If
                End If
'               Else
'               MyAnswerString = "False"
'               MyCellRow = MyCellRow + 1
            End If
        End If
    Next MyCellRow
'MsgBox MyCellColumnA
'RedFinder = Year(ActiveSheet.Cells(MyCellRow, MyCellColumn))
RedFinder = MyMoneyValue    'sets function to report total of MyMoneyValue
End Function

https://jsfiddle.net/DTcHh/25836/