0

私はJavaScriptの専門家でも、アマチュアでもありません。遊んでいるスクリプトを見つけて、コード内に2番目の変数を作成する方法を考えていました。

   <script type="text/javascript">
        $(document).ready(function(){
            $("select#type").attr("disabled","disabled");
            $("select#category").change(function(){
            $("select#type").attr("disabled","disabled");
            $("select#type").html("<option>wait...</option>");
            var id = $("select#category option:selected").attr('value');
            $.post("select_type.php", {id:id}, function(data){
                $("select#type").removeAttr("disabled");
                $("select#type").html(data);
            });
        });
    });
    </script> 

   <script type="text/javascript">
        $(document).ready(function(){
            $("select#model").attr("disabled","disabled");
            $("select#type").change(function(){
            $("select#model").attr("disabled","disabled");
            $("select#model").html("<option>wait...</option>");
            var id = $("select#type option:selected").attr('value');
            $.post("select_model.php", {id:id}, function(data){
                $("select#model").removeAttr("disabled");
                $("select#model").html(data);
            });
        });
    });
    </script> 

2番目のコードでは、カテゴリIDを取得し、$ _POST[cat_id]という別の投稿変数を作成します。同じjavacodeのselect_type.phpを参照して、これを再度行うにはどうすればよいですか?

これは、3ピースのチェーンドロップダウン用です。

ドロップ#1はドロップ#2を生成します。ドロップ#1と#2を一緒にすると、ドロップ#3が生成されます。

私が知る必要があるのは、最初のドロップダウンからそれを取得する2番目の変数を追加する方法です。

どんな助けでも大歓迎です。


編集:私はこのようなものをに追加しようとしましたが、機能しません。2番目の変数は、select_type.phpファイルのように、ドロップダウンの最初の最初の選択から取得する必要があります。または、何らかの方法で初期値を保存して持ち越し、3番目の選択を設定するのに役立てることができます。

   <script type="text/javascript">
        $(document).ready(function(){
            $("select#model").attr("disabled","disabled");
            $("select#type").change(function(){
            $("select#model").attr("disabled","disabled");
            $("select#model").html("<option>wait...</option>");
            var carrier = $("select#type option:selected").attr('value');
            $.post("select_model.php", {carrier:carrier}, function(data){
                $("select#model").removeAttr("disabled");
                $("select#model").html(data);
            });
            var countryid = $("select#category option:selected").attr('value');
            $.post("select_type.php", {countryid:countryid}, function(data){
                $("select#type").removeAttr("disabled");
                $("select#type").html(data);
            });         
        });
    });
    </script>  

何か助けはありますか?

4

2 に答える 2

0

編集 --- あなたの要求を誤解しました。最初のドロップボックスにイベント ハンドラーを設定する必要があります。次のようなことをさらに行う必要があります。

$.post("select_model.php", {carrier:carrier}, function(data){
    $("select#model").removeAttr("disabled").html(data);
});
$("select#category").change(function(){
    var countryid = $("select#category option:selected").attr('value');
    $.post("select_type.php", {countryid:countryid}, function(data){
        $("select#type").removeAttr("disabled").html(data);
    });
}); 
于 2012-08-11T02:52:59.883 に答える
0

これがあなたがそれを行う方法です。

var id = $("select#type option:selected").attr('value');
var categoryID = 34; 
$.post("select_model.php", {id:id, cat_id:categoryID}, function(data){
    $("select#model").removeAttr("disabled");
    $("select#model").html(data);
});

複数のドロップダウンについては、これを参照してください:複数選択ドロップダウンの処理方法 - JQuery。静的コンテンツを使用していますが、必要な ajax リクエストを間に追加して変更できることを願っています。

于 2012-08-11T05:07:48.200 に答える