Py.*_*Py. 6 javascript jquery jquery-mobile
我有一个使用jQuery构建的应用程序(并使用各种jQuery-UI工具).
出于某种原因,我必须将其移植到智能手机/平板电脑,并决定使用jQuery Mobile(为了尽量减少更改次数).
在我的vanilla应用程序中,我根据用户交互动态创建了页面的一些元素.
例如,可以像这样创建滑块(p是具有一堆参数的对象):
function createSlider(p){
return $("<div/>",{
"id":p.id,
"class":p.divClass,
}).slider({
"orientation": p.align,
"min":p.constraint.min,
"max":p.constraint.max,
"step":p.step,
"value":p.curVal,
"animate":"normal"
/*and some event handling here, but it doesn't matter*/
});
}
Run Code Online (Sandbox Code Playgroud)
它会产生一个漂亮的滑块.现在它看起来像:
function createSlider(p){
return $("<range/>",{
"id":p.id,
"class":p.divClass,
"min":p.constraint.min,
"max":p.constraint.max,
"step":p.step,
"value":p.curVal,
});
}
Run Code Online (Sandbox Code Playgroud)
但是,由于它是在动态创建的,jQuery Mobile在页面加载上完成的所有工作都没有在它上面完成.
有没有办法强制初始化而不在html中编写滑块?
谢谢.
编辑:我在文档中发现它可以实现使用container.trigger("create");
然而这还不行.
EDIT2:Ok create是解决方案.
根据文档(请参阅问题中的编辑),trigger("create")在包含元素上使用是有效的。
为了实现这一点,您还需要记住范围是输入类型而不是标签......
工作解决方案:
function createSlider(){
return $("<input/>",{
"type":"range",
"id":"sl",
"min":0,
"max":15,
"step":1,
"value":1,
});
}
function appendSlider(){
$("#yourdiv").append(createSlider()).trigger("create");
}
Run Code Online (Sandbox Code Playgroud)
顺便说一句,jQuery mobile 的文档缺少搜索选项。
| 归档时间: |
|
| 查看次数: |
4772 次 |
| 最近记录: |