2016-12-30 16 views
0

divをクリックすると、保存されたvarからテキストを削除しようとしています。jQueryで変数が変更されていません。

$(document).ready(function() { 

var allids = ''; 

    $("#artistselect").change(function() { 

    var id = $(this).children(":selected").attr("id"); 
    allids.push($(this).children(":selected").attr("value")); 

    selectid = "#" + id; 
    echoid = "#artistecho" + id; 

    $(echoid).show(300); 
    $(selectid).hide(0); 
    $("input[name=artistslist]").val(allids.join(", ")); 

    alert(allids); 

    }); 

    $(".remove").click(function() { 

    var removeid = $(this).attr("value"); 

    var allids = allids.replace(removeid, ''); 

    $('input[name=artistslist]').val(function(index, value) { 
     return value.replace(removeid, ''); 
    }); 



    alert(allids); 
    }); 
    }); 

この機能が正常に動作している:私のコードは次のようになります

$("#artistselect").change(function() { 

イムこの機能に問題がある:

$(".remove").click(function() { 

それはVaRのallidsを変更していない、またそれは私に警告(アリズ)を与えているのですか?

ありがとうございます。 ( "削除")

+0

'allids'配列はどこにも宣言されていません。 – Jai

+0

'allids.replace(removeid、 '')'が多分間違っていますか? 'allids'は配列ですか? – kukkuz

+0

'});'で文書準備関数を閉じてください。 – GRA0007

答えて

0

allidsは配列でなければならず、そのは再び$にVARとdecaledすべきではない。(関数を(クリック){

$(document).ready(function() { 

    var allids = []; 

     $("#artistselect").change(function() { 

     var id = $(this).children(":selected").attr("id"); 
     allids.push($(this).children(":selected").attr("value")); 

     selectid = "#" + id; 
     echoid = "#artistecho" + id; 

     $(echoid).show(300); 
     $(selectid).hide(0); 
     $("input[name=artistslist]").val(allids.join(", ")); 

     alert(allids); 

     }); 

     $(".remove").click(function() { 

     var removeid = $(this).attr("value"); 

     allids = allids.replace(removeid, ''); 

     $('input[name=artistslist]').val(function(index, value) { 
      return value.replace(removeid, ''); 
     }); 



     alert(newids); 
     }); 
     }); 
0

あなたは配列としてごallidsを定義する必要がありますここコードが & ECHOID変数ようselectid。

$(document).ready(function() { 

     var allids = []; 

     $("#artistselect").change(function() { 

     var id = $(this).children(":selected").attr("id"); 
     allids.push($(this).children(":selected").attr("value")); 

     var selectid = "#" + id; 
     var echoid = "#artistecho" + id; 

     $(echoid).show(300); 
     $(selectid).hide(0); 
     $("input[name=artistslist]").val(allids.join(", ")); 

     alert(allids); 

     }); 

     $(".remove").click(function() { 

     var removeid = $(this).attr("value"); 

     allids = allids.replace(removeid, ''); 

     $('input[name=artistslist]').val(function(index, value) { 
      return value.replace(removeid, ''); 
     }); 



     alert(newids); 
     }); 
     }) 
+0

をチェックすると、変更されません。それは今私にアラート(アリズ)を与えている。 – Dustin

関連する問題