私はこのjQueryのイベントハンドラのコードを持っていたし、私は機能このjQuery関数で何が問題になっていますか?
$("#activate-user").click(function() {
var userId = [];
$(':checkbox:checked').each(function(i) {
userId[i] = $(this).val();
});
if(userId.length == 0) {
//If userId is empty
} else {
$.ajax({
type: 'POST',
url: 'process.php',
data: 'option=activate&userId='+userId,
success: function(msg){
if(msg == 0) {
//If cannot process the query.
} else {
//If query is processed.
location.reload(true);
}
}
});
}
});
$("#block-user").click(function() {
var userId = [];
$(':checkbox:checked').each(function(i) {
userId[i] = $(this).val();
});
if(userId.length == 0) {
//If userId is empty
} else {
$.ajax({
type: 'POST',
url: 'process.php',
data: 'option=block&userId='+userId,
success: function(msg){
if(msg == 0) {
//If cannot process the query.
} else {
//If query is processed.
location.reload(true);
}
}
});
}
});
この2つのイベントハンドラとの唯一の違いはある、option=
data: 'option=activate&userId='+userId
data: 'option=block&userId='+userId
すなわち値に変換したいです
これをjQuery functioに変換したい私は正しく引数を渡すわけではないとして、これは、動作しているようですしない
$('#activate-user').userOperation(function() {
return 'block';
});
:N
(function ($) {
jQuery.fn.userOperation = function(opString) {
this.click(function() {
var userId = [];
$(':checkbox:checked').each(function(i){
userId[i] = $(this).val();
});
if(userId.length === 0) {
//If userId is empty.
} else {
$.ajax({
type: 'POST',
url: 'process.php',
data: 'option='+opString+'&userId='+userId,
success: function(msg){
if(msg == 0) {
//If cannot process the query.
} else {
//If query is processed.
location.reload(true);
}
}
});
}
});
}
}(jQuery));
jQueryの関数呼び出し、私はまったく動作しないこの方法をやってみましたため私はjQueryの初心者ですから、どうやってこれを行うのか分かりません。どこが間違っていますか?これはjQuery関数に引数を渡す正しい、実行可能な方法ですか?
は1 .. FOR
ほとんどのコードは私には見えません:D、申し訳ありませんがjQueryの初心者です。あなたのアドバイスを広げることができたらうれしく思います。 –
@ibrahim:私ちょうどあなたのためにそれをコメントしました。 ;-) –
あなたのようなものです、ありがとう:) –