如果通过 jquery 选中复选框,则不会被选中
$("#submit_load").click(function() {
var profilename =$("#search_profiles option:selected").attr("value");
var data='profilename='+profilename+'&user_id=' + <?=$user_id;?>;
alert(data);
$.ajax({
//this is the php file that processes the data and send mail
url: "getprofile.php",
type: "POST",
data: data,
cache: false,
success: function (html) {
alert(html);
var dia_info = html.split('~');
//$('#diamond_options')[0].reset();
var dia_id = $(':checkbox:checked.ds_nobg').map(function() {
return this.id;
}).get().join(',');
alert("diatype----"+dia_id);
// alert(dia_id.length);
if(dia_id.length>0)
{
var dia_id_arr = dia_id.split(',');
for(var j=0;j<dia_id_arr.length;j++)
{
var chk_id = dia_id_arr[j];
var diashape_chk = '#' + chk_id;
var bg_id='#'+chk_id+'1';
var shape_id='#'+chk_id+'-1';
var shape_class_on=chk_id+'_1_on';
var shape_class_off=chk_id+'_1';
// alert(chk_id+'---'+diashape_chk+'---'+bg_id+'---'+shape_id+'---'+shape_class_on+'---'+shape_class_off );
// alert(dia_id_arr_sp[0]+'---'+dia_id_arr_sp[1]+'---'+diashape_chk+'---'+diashape+'---'+remclass+'---'+addcls+'---'+rembg );
// alert(diashape);
$(shape_id).removeClass(shape_class_on);
$(shape_id).addClass(shape_class_off);
$(bg_id).removeClass('ds_bg_hi' );
$(bg_id).addClass('ds_nobg' );
$(diashape_chk).removeAttr('checked') ;
if ($(shape_id).hasClass(shape_class_off)) {
alert("helllo---"+j+"---"+shape_id);
}
}
}
if(dia_info[34].length>0)
{
var dia_id_arr = dia_info[34].split(',');
for(var l=0;l<dia_id_arr.length;l++)
{
var chk_id = dia_id_arr[l];
var diashape_chk = '#' + chk_id;
var bg_id='#'+chk_id+'1';
var shape_id='#'+chk_id+'-1';
var shape_class_on=chk_id+'_1_on';
var shape_class_off=chk_id+'_1';
if ($(shape_id).hasClass(shape_class_off)) {
alert("ddddd---"+l+"---"+shape_id);
}
// alert(chk_id+'---'+diashape_chk+'---'+bg_id+'---'+shape_id+'---'+shape_class_on+'---'+shape_class_off );
$(shape_id).removeClass(shape_class_off);
$(shape_id).addClass(shape_class_on);
$(bg_id).removeClass('ds_nobg' );
$(bg_id).addClass('ds_bg_hi' );
$(diashape_chk).attr('checked', 'checked') ;
if ($(shape_id).hasClass(shape_class_on)) {
alert("eeee---"+l+"---"+shape_id);
}
}
}
});
});
抱歉,伙计们,我在这个问题上做得不好......正如你所看到的,我 $('#diamond_options')[0].reset();这导致了我评论过的所有问题,一切都有效......
$("#submit_load").click(function() {
var profilename =$("#search_profiles option:selected").attr("value");
var data='profilename='+profilename+'&user_id=' + <?=$user_id;?>;
alert(data);
$.ajax({
//this is the php file that processes the data and send mail
url: "getprofile.php",
type: "POST",
data: data,
cache: false,
success: function (html) {
alert(html);
var dia_info = html.split('~');
//$('#diamond_options')[0].reset();
var dia_id = $(':checkbox:checked.ds_nobg').map(function() {
return this.id;
}).get().join(',');
alert("diatype----"+dia_id);
// alert(dia_id.length);
if(dia_id.length>0)
{
var dia_id_arr = dia_id.split(',');
for(var j=0;j<dia_id_arr.length;j++)
{
var chk_id = dia_id_arr[j];
var diashape_chk = '#' + chk_id;
var bg_id='#'+chk_id+'1';
var shape_id='#'+chk_id+'-1';
var shape_class_on=chk_id+'_1_on';
var shape_class_off=chk_id+'_1';
// alert(chk_id+'---'+diashape_chk+'---'+bg_id+'---'+shape_id+'---'+shape_class_on+'---'+shape_class_off );
// alert(dia_id_arr_sp[0]+'---'+dia_id_arr_sp[1]+'---'+diashape_chk+'---'+diashape+'---'+remclass+'---'+addcls+'---'+rembg );
// alert(diashape);
$(shape_id).removeClass(shape_class_on);
$(shape_id).addClass(shape_class_off);
$(bg_id).removeClass('ds_bg_hi' );
$(bg_id).addClass('ds_nobg' );
$(diashape_chk).removeAttr('checked') ;
if ($(shape_id).hasClass(shape_class_off)) {
alert("helllo---"+j+"---"+shape_id);
}
}
}
if(dia_info[34].length>0)
{
var dia_id_arr = dia_info[34].split(',');
for(var l=0;l<dia_id_arr.length;l++)
{
var chk_id = dia_id_arr[l];
var diashape_chk = '#' + chk_id;
var bg_id='#'+chk_id+'1';
var shape_id='#'+chk_id+'-1';
var shape_class_on=chk_id+'_1_on';
var shape_class_off=chk_id+'_1';
if ($(shape_id).hasClass(shape_class_off)) {
alert("ddddd---"+l+"---"+shape_id);
}
// alert(chk_id+'---'+diashape_chk+'---'+bg_id+'---'+shape_id+'---'+shape_class_on+'---'+shape_class_off );
$(shape_id).removeClass(shape_class_off);
$(shape_id).addClass(shape_class_on);
$(bg_id).removeClass('ds_nobg' );
$(bg_id).addClass('ds_bg_hi' );
$(diashape_chk).attr('checked', 'checked') ;
if ($(shape_id).hasClass(shape_class_on)) {
alert("eeee---"+l+"---"+shape_id);
}
}
}
});
});
sorry fellas my bad on this problem ....as you can see I $('#diamond_options')[0].reset(); which was causing all the problems i have commented that an it all works....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更好地处理最新的 jQuery v1.6 方法 jQuery.prop 和 < a href="http://api.jquery.com/removeprop/" rel="nofollow">jQuery.removeProp
Better to deal with latest jQuery v1.6 methods jQuery.prop and jQuery.removeProp