this.value现在是$("#style_background"),我需要将其更改为$(" .selector")值。我怎么能这样做。
$("#style_background").click(function(){
if ($(".selector").is(":checked")) {
document.cookie = "background=" + this.value + ";" + "path=/";
disable($('#style_background'));
notification('success', 'record updated successfuly', 'topRight');
} else {
disable($('#style_background'));
notification('alert', 'restart your browser', 'topRight');
}
});
答案 0 :(得分:1)
$("#style_background").click((function(){
if ($(".selector").is(":checked")) {
document.cookie = "background=" + this.value + ";" + "path=/";
disable($('#style_background'));
notification('success', 'record updated successfuly', 'topRight');
} else {
disable($('#style_background'));
notification('alert', 'restart your browser', 'topRight');
}
}).bind($(".selector")[0]));
您可能希望使用bind功能来指定“这个”'函数内部的值。
答案 1 :(得分:0)
据我了解,您想要从html触发复选框。 (如果你提供这个代码也会更好):
$(".selector").change(function(){
if ($(".selector").is(":checked")) {
document.cookie = "background=" + this.value + ";" + "path=/";
disable($('#style_background'));
notification('success', 'record updated successfuly', 'topRight');
} else {
disable($('#style_background'));
notification('alert', 'restart your browser', 'topRight');
}
});