jquery 在滑块上验证
表单有几个滑块以及其他输入。
所有其他输入都会验证 find,但验证 jquery slider
时遇到问题 添加滑块的代码
$(".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>
Form has several sliders along with other inputs.
All other inputs validates find, but having problem validating jquery slider
Code to add slider
$(".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();
});
}
});
});
Here is one of the fieldsets that get generated
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我注意到两件事:
1:您在
$.each()
内声明$("#slider", this).slider({..
),这意味着您可以每次迭代都会覆盖 #slider 上的参数2:您正在使用
$(this).closest('fieldset').find('input:text').val(ui.value);
里面的change: function(){}
可能无法正确遍历,特别是当它正在查找 #select 并且有多个时。Two things I notice:
1: You are declaring
$("#slider", this).slider({..
inside an$.each()
which means you could be overwriting your parameters on #slider each iteration.2: You are using
$(this).closest('fieldset').find('input:text').val(ui.value);
inside thechange: function(){}
which might not be traversing correctly, especially if it's looking for #select and there are more than one.