如何在JQuery Mobile中动态刷新复杂的div? [英] How do I dynamically refresh complex divs in JQuery Mobile?

查看:44
本文介绍了如何在JQuery Mobile中动态刷新复杂的div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据用户输入显示div一定次数(1-5次).我最初尝试仅使用javascript来存储内部html的副本;每当用户更改数字(1-5)时,我会将数字传递给javascript方法,该方法将清空div,然后将内部html的副本粘贴多次(传递的数字)在div中.这似乎可以产生没有JQuery Mobile样式的普通香草javascript输出,并且我还无法获得一种刷新方法.

I want to display a div a set number of times (1-5 times) based on user input. I originally tried just using javascript to store a copy of the inner html; whenever the user changed the number (1-5), I would pass the number to a javascript method which would empty the div then paste the copy of the inner html that many times (the number passed) within the div. This appears to produce plain vanilla javascript output without JQuery Mobile styles, and I haven't been able to get a refresh method to work.

var content = $('.someClass').html();

function setNumDivs( numDivs ){
$('.someClass').html("");
for(var i=0; i<numDivs; i++){
    $('.someClass').append(content);
}   
}

这是我要根据用户输入重复的div(1-5次)(例如,用户应能够从3更改为5,然后再返回1,并重复div并显示动态次数而不刷新页面):

This is the div I am trying to repeat (1-5 times) depending on user input (a user should be able to change from 3 to 5 then back to 1, for example, and have the div repeated and displayed that number of times dynamically without a page refresh):

<div class="someClass">
<label for="selectionButton" class="select"></label>
<select name="selectionButton" id="selectionButton">
        <option value="default">Select a major</option>
        <option value="option1">Option 1</option>
        <option value="option2">Option 2</option>
        <option value="option3">Option 3</option>
</select>

<span id="someSlider" data-role="fieldcontain"> %     
    <input type="range" name="slider" id="slider" value="50" min="1" max="100"/>       
</span>

推荐答案

您需要刷新" div.尝试使用

you'll need to 'refresh' the div. try using

.trigger('create') 

就可以了.查看文档.

这篇关于如何在JQuery Mobile中动态刷新复杂的div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆