jQuery mobile,当表单元素输入类型为“时显示消息”;“范围”;值为最大值

jQuery mobile,当表单元素输入类型为“时显示消息”;“范围”;值为最大值,jquery,jquery-mobile,Jquery,Jquery Mobile,我正在jQuery mobile中创建一个表单,并使用表单元素input type=“range”。当选择“最大值”时,我希望在下面的范围中显示一条消息,如“Ok,this value or more”。支持多个范围的通用函数最有用。这样的功能是如何实现的 <label>Highest price? <input type="range" name="highest_price" id="highest_price" data-highlight="true" step

我正在jQuery mobile中创建一个表单,并使用表单元素input type=“range”。当选择“最大值”时,我希望在下面的范围中显示一条消息,如“Ok,this value or more”。支持多个范围的通用函数最有用。这样的功能是如何实现的

<label>Highest price?
    <input type="range" name="highest_price" id="highest_price" data-highlight="true" step="500" value="38000" min="2000" max="40000" size="29"/>
</label>
最高价格?

这里有一个我放在一起的选项,它是一个函数,可以处理表单中的多个范围字段。可以使用$(document).on('slidestop'等)进行改进

<label>Highest price?
    <input type="range" name="highest_price" id="highest_price" data-highlight="true" step="500" value="38000" min="2000" max="40000" size="29"/>
</label>
<label>When?
    <input type="range" name="withindays" id="withindays" data-highlight="true" step="1" value="5" min="1" max="20" size="29"/>
</label>

<script>
//Gives msg when value is max in range
function nyakilian_range_max_msg (thisinput){
    thisinputspan = thisinput+'_span';
    thisinput = '#' + thisinput;
    maxvalue = jQuery(thisinput).attr('max');
    slider_value = jQuery(thisinput).val();
    if(slider_value == maxvalue){   
        jQuery('#'+thisinputspan).fadeIn();
        jQuery('#form_search_txrn_milage_span').fadeIn();
    } else {  
        jQuery('#'+thisinputspan).hide();
    }
}
function nyakilian_range_max_msg_init(thisinput, mess) {
    jQuery('#'+ thisinput).parent().change( function() {
        nyakilian_range_max_msg(thisinput);
    });
    jQuery('#'+ thisinput).after('<span id="' + thisinput + '_span" style="display: none;">'+mess+'</span>');
}

nyakilian_range_max_msg_init('highest_price', 'Alright that\'s max! ');
nyakilian_range_max_msg_init('withindays', 'Alright before that or later! ');

</script>
最高价格?
什么时候
//当值在范围内为最大值时给出消息
函数nyakilian_range_max_msg(此输入){
thisinputspan=thisinput+“u span”;
thisinput='#'+thisinput;
maxvalue=jQuery(thisinput).attr('max');
slider_value=jQuery(thisinput).val();
如果(滑块_值==最大值){
jQuery('#'+thisinputspan).fadeIn();
jQuery('#form#u search_txrn_milage_span').fadeIn();
}否则{
jQuery('#'+thisinputspan).hide();
}
}
函数nyakilian_range_max_msg_init(此输入,mess){
jQuery('#'+thisinput).parent().change(函数(){
nyakilian_range_max_msg(此输入);
});
jQuery('#'+thisinput).after(''+mess+'');
}
nyakilian_range_max_msg_init('最高价格','好吧,那就是max!');
nyakilian_range_max_msg_init('within days','OK before that or later!');
工作示例:

$(document).on('pagebeforeshow','#index',function(){
nyakilian_range_max_msg_init(“#最高价格”,“好吧,那就是max!”);
nyakilian_range_max_msg_init('within days','OK before that or later!');
});
函数nyakilian_range_max_msg_init(thisinput,msg){
$(document).on('slidestop',thisinput,function(){
if($(this.val()==$(thisinput.attr('max')){
$(this).parent()在(''+msg+'')之后;
$(this.parent().parent().find('.slider msg').fadeIn();
}否则{
if($(this).parent().parent().find('.slider msg').length>0){
$(this.parent().parent().find('.slider msg').fadeOut().remove();
}
}
});    
}

只是一个想法,我们可以添加
好的,这个价格…
因为这是一种错误的东西。这只是一个概念证明。Carl可以根据自己的需要设计样式,但我喜欢你的想法。关于你的更新,再看看我的例子,我会更新我的答案。如果是这样,请告诉我。
$(document).on('pagebeforeshow', '#index', function(){ 
    nyakilian_range_max_msg_init('#highest_price', 'Alright that\'s max! ');
    nyakilian_range_max_msg_init('#withindays', 'Alright before that or later! ');     
});

function nyakilian_range_max_msg_init(thisinput, msg) {
    $(document).on('slidestop', thisinput, function(){ 
        if($(this).val() == $(thisinput).attr('max')) {
            $(this).parent().after('<span class="slider-msg">'+ msg +'</span>');
            $(this).parent().parent().find('.slider-msg').fadeIn();
        } else {
            if($(this).parent().parent().find('.slider-msg').length > 0 ) {
                $(this).parent().parent().find('.slider-msg').fadeOut().remove();
            }
        }
    });    
}