$('#checkyes').prop('checked', row['checkb']);
var check = row['checkb'];
alert(check);
$('#checkyes').checkboxradio('refresh');
The alert correctly shows the value inside row['checkb'] to be false, yet the checkbox gets ticked anyway. Am I missing some quotations somewhere or can I not use the row value?
var isResult = (row['checkb'] == 0) ? false : true;
$('#checkyes').prop('checked', isResult);
$('#checkyes').prop('checked', JSON.parse(row['checkb']));
Try
$('#checkyes').prop('checked', (row['checkb'] == 'true') ? true : false);
Or
$('#checkyes').prop('checked', (row['checkb'] == 'true') );
var chk = (row['checkb'] == 'true') ? true : false; //Or var chk = (row['checkb'] == 'true'); $('#checkyes').prop('checked', chk );
row['checkb']
has value string true
or false
not Boolean value .
So $('#checkyes').prop('checked', row['checkb']);
will evaluate to checked.
String value here prop('checked', String)
makes it true for all cases .
根据Tushar Gupta的回答,我建议:
$('#checkyes').prop('checked', row['checkb'] == 'true');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.