2017-06-22 6 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

は、「セレクタ」あなたはおそらく '$(にbind''に意味のparam – 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])); 

あなたは、関数内のthisの値を指定するためにbind機能を使用する場合があります。

+1

としてDOM要素を渡して関数としてコードを書きます)[0] '、jQueryのコンテキストではありません – haim770

+0

私は.selectorで8つのクラスを持っています。これは最初の値を取得するだけです。私はこれと一緒に使う必要があります。 – 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

関連する問題