我在页面中动态创建了我的复选框.我想为动态创建的所有复选框添加click事件.
这是我的代码.
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" id="br">
</fieldset>
</div>
Run Code Online (Sandbox Code Playgroud)
我动态创建了复选框并附加到fieldset.
$.getJSON("http://localhost/WebSite/",
function(data){
var branchOp="";
$.each(data.branch, function(i,item){
branchOp += '<input type="checkbox" name="branch" id="'+item.branchCode+'" value="'+item.branchCode+'" class="branch"><label for="'+item.branchCode+'">'+item.branchName+'</label>';
$(item.branchCode).addClass("intro");
});
$('#br').append(branchOp).trigger( "create" );
});
Run Code Online (Sandbox Code Playgroud)
我使用on(),live(),deligate()方法在复选框上添加事件处理程序.
$('#br').delegate('click','input:checkbox', function(event) {
alert('selected');
});
$('#br').on('click','input:checkbox', function(event) {
alert('selected');
});
Run Code Online (Sandbox Code Playgroud)
没有什么对我有用......
我正在创建一个jQuery移动应用程序.Icons没有出现在我的任何页面中.
这是代码
<link rel="stylesheet" href="css/jquery.mobile.min.css" />
<script src="script/jquery-1.7.1.min.js"></script>
<script src="script/jquery.mobile.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
但是当我使用CDN托管文件时其工作正常.为什么会这样?
我想通过$.getJSON调用填充表格:
$.getJSON("localhost/url",
function (data) {
$.each(data.reporting_list.reporting, function (i, item) {
rows = '<tr><td>' + item.data1 + '</td><td>' + item.data2 + '</td></tr>'
});
$('#aaa').append(rows);
});
Run Code Online (Sandbox Code Playgroud)
填充后我想激活一些页面更改:
$.mobile.changePage("#homePage");
Run Code Online (Sandbox Code Playgroud)
但页面在$.getJSON完成之前发生了变化.
我想在$.getJSON完成后更改页面并改为显示ajaxloader.