2017-06-22 29 views
0

this.value现在是$(“#style_background”),我需要将其更改为$(“。selector”)值。我怎样才能做到这一点。如何在点击功能中使用this.value其他元素

$("#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

写传递一个DOM元素作为帕拉姆 – ThisGuyHasTwoThumbs

回答

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

你大概意思'bind'到'$(“选择”的代码作为函数)[0]',而不是jQuery上下文 – haim770

+0

我有8个类.selector。这只是获得第一个价值。我必须使用这个。 – d3esligner

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'); 
    } 
}); 
+0

我有8个背景,我有一个保存按钮。我必须使用#style_background – d3esligner

相关问题