【发布时间】:2016-11-29 17:00:45
【问题描述】:
我正在尝试将一些动态生成的代码添加到使用 Jquery Mobile 的现有 HTML 文件中:
<div data-role="page" id="page">
Click on the button
<a href="#section" id="abutton" data-role="button">Add item</a>
<label for="id" id="id-label">ID:</label>
<input type="text" id="id" name="id" value="" />
<label for="name" id="name-label">Name:</label>
<input type="text" id="name" name="name" value="" />
</div>
问题是当我添加一些代码时,新代码与现有代码的外观不同:
$('#abutton').click(function(){
var code = '<label for="surname" id="surname-label">Surname:</label>' +
'<input type="text" id="surname" name="surname" value="" />';
$("#page").append(code);
return false;
});
我一直在研究,发现非动态生成的 HTML 代码添加了一些标签和类。我想我必须调用一些函数来解析新的动态生成的代码,但是哪个?还是我应该做一些完全不同的事情?
Demo here:我添加了一个动态生成的来显示 jquery mobile 生成的其他结构,仅添加一些类就无法解决。
【问题讨论】:
-
$("#page").append(code).enhanceWithin(); -
是的@Omar,这就是答案!请把它放在一个答案中以接受它作为一个好的答案:)
标签: jquery html jquery-mobile dynamically-generated