jquery
  • jquery-validate
  • 2011-08-14 25 views 1 likes 
    1

    表單有幾個滑塊以及其他輸入。在滑塊上驗證jquery

    所有其他輸入驗證發現,但有問題的驗證jQuery的滑塊

    代碼添加滑塊

    $(".jSlider").each(function(){ 
        var id = $(this).attr("id"); 
        var sliderID = id + "_slider"; 
        var newSlider = '<div style="padding-top:30px;padding-right:10px;background: #fff url(/images/scrollerBg.png) no-repeat;" id="sliderContainer" ><div style="background: #555" id="slider"></div></div><br />'; 
        $(this).append(newSlider); 
        $(this).closest('fieldset').find('input:text').css("display", "none"); 
        $("#slider", this).slider({ 
         value:0, 
         min: 0, 
         max: 10, 
         orientation: "horizontal", 
         range: "min", 
         step: 1, 
         animate: true, 
         change: function(event, ui) { 
          $(this).closest('fieldset').find('input:text').val(ui.value); 
           // was adding error manually cause of background image being used 
          $(this).closest('fieldset').find('div.jSliderError').slideUp('fast', function(){ 
           $(this).remove(); 
          }); 
          } 
    
        }); 
    
        }); 
    

    這裏是獲取生成

    <fieldset class="q_default required jSlider fixFirefox" id="q_423" name="8) On a scale of 0 to 10 how did you like it?"><legend><span>8) On a scale of 0 to 10 how did you like it?</span></legend><ol><span class='help'></span> 
        <input id="r_8_question_id" name="r[8][question_id]" type="hidden" value="423" /> 
    
    
        <input class="" id="r_8_answer_id" name="r[8][answer_id]" type="hidden" value="8782" /> 
        <li class="string optional" id="r_8_string_value_input"><input id="r_8_string_value" maxlength="255" name="r[8][string_value]" type="text" /></li> 
        </ol></fieldset> 
    

    回答

    2

    東西兩個字段集的一個我通知:

    1:您聲明$("#slider", this).slider({..$.each()之內,這意味着您可以在每次迭代時覆蓋#slider上的參數。

    2:您在change: function(){}內部使用$(this).closest('fieldset').find('input:text').val(ui.value);,這可能無法正確遍歷,特別是如果它正在查找#select並且存在多個。

    +0

    你說的很對,但是我正在試着去理解一個新的寶石。但你確實找到了我的答案。添加到我的js'$(this).closest('fieldset')。find('input:text')。addClass('required');'到隱藏字段將確保隱藏的實際值輸入字段。謝謝。 – pcasa

    +0

    很高興幫助! :) – AlienWebguy

    相關問題