- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个大问题:我有一个 listview
,每个项目都链接到页面 #concorsi
。当我单击链接时,URL 会变为 #concorsi?numero=1
,因为我正在从 JSON 中获取表单编号 1。
当我第一次点击时一切正常。每个输入都使用 jQuery Mobile 类进行可视化,但如果我返回并进入同一链接后,代码不会刷新。标题很直观,但内容没有。如何强制刷新div内容?
这些是我的 JavaScript 函数:
<script type="text/javascript">
$(document).bind( "pagebeforechange", function( e, data ) {
// We only want to handle changePage() calls where the caller is
// asking us to load a page by URL.
if ( typeof data.toPage === "string" ) {
// We are being asked to load a page by URL, but we only
// want to handle URLs that request the data for a specific
var u = $.mobile.path.parseUrl( data.toPage ),
re = /^#concorso/;
if ( u.hash.search(re) !== -1 ) {
// We're being asked to display the items for a specific category.
// Call our internal method that builds the content for the category
// on the fly based on our in-memory category data structure.
showConcorso( u, data.options);
// Make sure to tell changePage() we've handled this call so it doesn't
// have to do anything.
e.preventDefault();
}
}
});
</script>
和showConcorso()
L
function showConcorso( urlObj, options )
{
document.getElementById('conccont').innerHTML="";
var concorsoNum = urlObj.hash.replace( /.*numero=/, "" ),
// Get the object that represents the category we
// are interested in. Note, that at this point we could
// instead fire off an ajax request to fetch the data, but
// for the purposes of this sample, it's already in memory.
concorso = obj.concorsi[ concorsoNum ],
// The pages we use to display our content are already in
// the DOM. The id of the page we are going to write our
// content into is specified in the hash before the '?'.
pageSelector = urlObj.hash.replace( /\?.*$/, "" );
if ( concorso ) {
// Get the page we are going to dump our content into.
var $page = $( pageSelector ),
// Get the header for the page.
$header = $page.children( ":jqmData(role=header)" ),
// Get the content area element for the page.
$content = $page.children( ":jqmData(role=content)" ),
$footer = $page.children( ":jqmData(role=footer)" );
// Find the h1 element in our header and inject the name of
// the category into it.
$header.find( "h1" ).html(concorso['title']);
markup=document.createElement('form');
markup.setAttribute('action','#home');
markup.setAttribute('method','POST');
markup.id="concForm";
markup.onchange="alert (test)";
items=obj.concorsi[concorsoNum].elementi;
for(field in items) {
nest=items[field];
nest=obj.campi[nest];
switch(nest.type){
case "free": markup.appendChild(createFree(nest));
break;
case "text": markup.appendChild(createText(nest));
break;
case "textarea": markup.appendChild(createTextArea(nest));
break;
case "switch": markup.appendChild(createSwitch(nest));
break;
case "switchcust": markup.appendChild(createSwitchCustom(nest));
break;
case "slider": markup.appendChild(createSlider(nest));
break;
case "select": markup.appendChild(createSelect(nest));
break;
case "checkbox": markup.appendChild(createCheckbox(nest));
break;
case "radio": markup.appendChild(createRadio(nest));
break;
case "reset": markup.appendChild(createButton(nest));
break;
case "submit": markup.appendChild(createButton(nest));
break;
}
}
// Inject the category items markup into the content element.
$content.html( markup );
// Pages are lazily enhanced. We call page() on the page
// element to make sure it is always enhanced before we
// attempt to enhance the listview markup we just injected.
// Subsequent calls to page() are ignored since a page/widget
// can only be enhanced once.
$page.page();
// We don't want the data-url of the page we just modified
// to be the url that shows up in the browser's location field,
// so set the dataUrl option to the URL for the category
// we just loaded.
options.dataUrl = urlObj.href;
// Now call changePage() and tell it to switch to
// the page we just modified.
$.mobile.changePage( $page, options );
}
}
最佳答案
刷新页面用户:
.trigger('create');
更多信息请参见:
Create vs. refresh: An important distinction
Note that there is an important difference between the create event and refresh method that some widgets have. The create event is suited for enhancing raw markup that contains one or more widgets. The refresh method should be used on existing (already enhanced) widgets that have been manipulated programmatically and need the UI be updated to match.For example, if you had a page where you dynamically appended a new unordered list with data-role=listview attribute after page creation, triggering create on a parent element of that list would transform it into a listview styled widget. If more list items were then programmatically added, calling the listview’s refresh method would update just those new list items to the enhanced state and leave the existing list items untouched.
您还可以像这样刷新 ListView :
$('#mylist').listview('refresh');
更多信息请参见:
Updating lists
If you add items to a listview, you'll need to call the refresh() method on it to update the styles and create any nested lists that are added. For example:$('#mylist').listview('refresh');
Note that the refresh() method only affects new nodes appended to a list. This is done for performance reasons. Any list items already enhanced will be ignored by the refresh process. This means that if you change the contents or attributes on an already enhanced list item, these won't be reflected. If you want a list item to be updated, replace it with fresh markup before calling refresh.
刷新表单元素:
Refreshing form elements
In jQuery Mobile, some enhanced form controls are simply styled (inputs), but others are custom controls (selects, sliders) built from, and kept in sync with, the native control. To programmatically update a form control with JavaScript, first manipulate the native control, then use the refresh method to tell the enhanced control to update itself to match the new state. Here are some examples of how to update common form controls, then call the refresh method:
复选框:
$("input[type='checkbox']").prop("checked",true).checkboxradio("refresh");
radio :
$("input[type='radio']").prop("checked",true).checkboxradio("refresh");
选择:
var myselect = $("#selectfoo");
myselect[0].selectedIndex = 3;
myselect.selectmenu("refresh");
slider :
$("input[type='range']").val(60).slider("refresh");
翻转开关(它们使用 slider ):
var myswitch = $("#selectbar");
myswitch[0].selectedIndex = 1;
myswitch.slider("refresh");
可折叠:
$('div[data-role=collapsible]').collapsible();
关于Jquery移动: Forcing refresh of content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8357756/
什么是 SASS 方法要求干燥这样的东西: .content p, .content ul, .content li, .content a 最佳答案 这 4 个元素都有共同的样式吗? .conten
我正在评估 Contentful.com 作为 Angular SPA 的内容引擎。 我面临的问题是按内容类型检索条目(例如,获取“博客”类型的所有条目)。如 documentation exampl
在我编辑的主 wiki 上有一个名为 Item: 的自定义命名空间,提示是该命名空间内的每个页面都显示为 Item:This_item - - Item:That_item -- Item:Foo_i
我正在尝试编写一个Python脚本,可以将图片和pdf上传到WordPress。我希望图像上传到文件夹‘/wp-Content/Uploads/’,将pdf文件上传到文件夹‘/wp-Content/U
是否可以监控进行了多少次 Contentful API 调用,并理想地在即将超过配额时收到通知? 谢谢 最佳答案 当然,您可以在右侧用户配置文件的下拉菜单 > Organizations and Bi
我在尝试在 IE8 中下载带有分号的文件名时遇到问题。 Response.AddHeader("Content-Disposition", "attachment; filename=\"" + at
我在 Contentful Delivery API 中运行查询以返回基于它的 slug 的特定页面项目。这个查询还设置了语言环境,以便它只返回我需要呈现的语言的数据。 但是,我还需要设置页面的 hr
我有兴趣使用 Gatsby建一个Netlify使用来自 Contentful 的内容的静态网站 Netlify 有这个不错的 Gatsby 入门指南: https://www.netlify.com/
目标是提交一个 git 分支。分支的“git status”的输出是: On branch zeromq_new Your branch is up to date with 'origin/zero
我目前正在学习在 ASP.NET 3.5 和 C# 中使用 MasterPages 和 ContentPlaceHolders - 现在,我正在拼命尝试通过我的编程代码编辑 asp:Content-C
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我使用 bootstrap 3 作为我的网格框架和 CSS 来创建一个具有一个倾斜/倾斜边缘的半透明区域,但由于分层不透明度,我的元素遇到了问题。 期望是中心是倾斜的,但右侧仍然是正方形。 有没有更好
IllegalArgumentException: 未知 URL 内容:// ^ 对上述内容做了噩梦。我检查了我的变量和路径,但看不出问题是什么?非常感谢任何指点! 这是我的痕迹。 java.lan
我有两个元素:一个是 元素,另一个是 元素。 populated-drop-down extends drop-down ,但是,正如您可能已经猜到的那样,它会尝试使用一些选项预先填充它。假设我可以简
我想我也有同样的问题。 Using multiple yields to insert content 我尝试了这个解决方案。我试过 在我的 application.html.erb 中有 conte
此链接 ( https://css-tricks.com/snippets/css/a-guide-to-flexbox/ ) 表示 justify-content 和 align-content 的
我现在正在探索绑定(bind),并且有一个 NSPopUpButton - 它为我提供了一些值选择下的绑定(bind)选项 - Content , Content Objects , Content
正在尝试在内容页面中加载内容 View 。当我运行代码时,它不会出现在我的内容 View 中。我正在从我的内容页面分配两个可绑定(bind)参数。 内容页面: 内容 View :
我想从我的 :before 标签中获取 content。我知道有些人会说它不是真正的(伪)元素,但在 JS 中有一种方法,但有人可以帮助我在 JQ 中做到这一点,因为我有多个标签并且我想用 $.eac
我创建了一个.sh脚本,并将结果记录在一个文件中,执行后我会尝试将文件内容作为mail正文发送。 这是我运行的命令: sh update.sh >> update.$(date +"%Y-%m-%d:
我是一名优秀的程序员,十分优秀!