是否可以将jQuery UI主题(Combobox,按钮)添加到动态元素

时间:2014-02-05 22:32:51

标签: jquery jquery-ui

Ex:插入页面时,动态选择框或按钮(来自ajax响应)应以jQuery UI ComboBox样式或jQuery UI Button样式呈现。

$.get("someurl", function(html){
  $("p").append(html); 
 // at this point the selectbox & button should be rendered as 
 // jQuery UI combobox & jQuery UI Button 
}

被修改

响应html包含带有textfield列表的表单,selectbox&按钮

<select name="scope" >
 <option value="in">in</option>
 <option value="out">out</option>
</select>

<div class="buttonContainer">
 <button name="save">Save</button>
 <button name="cancel">Cancel</button>               
</div>

在添加html之后,我想使用$(“select”)。combobox()来设置选择框的样式。在我的主页面(js文件)中,我已经在文档就绪方法中添加了以下行。

 $("select").combobox() 
 $("button").button() 

像jQuery有 .on()将事件处理函数附加到动态元素。以同样的方式可以将UI主题(组合框,按钮)添加到动态元素中吗?

更新

我想在加载页面html时会触发一个事件(通过ajax)。 http://jsfiddle.net/ECJ8N/

$("body").bind( "uirender", function() {
    $("select").combobox(); 
    $("button").button() ;           
});

和ajax响应会做

$.get("someurl", function(html){
  $("p").append(html).trigger("uirender");
}

有没有比这更好的方法?

0 个答案:

没有答案