选择下拉列表后如何更改标签值

时间:2014-12-27 10:51:16

标签: jquery python django

我正在创建python项目我在models.py中创建了下拉字段,然后我必须在html模板中显示。我也写了jquery代码。但是dint work。

models.py

addtype = models.CharField(max_length=25,choices=STATE_CHOICES,default='seller') 

forms.py

 addtype = forms.ModelChoiceField(queryset=type.objects.all())

views.py

addtype = product_form.cleaned_data['addtype'] 

ad.html

<head>

    <script  src="../static/js/jquery-1.9.1.js"></script>
     <script type="text/javascript">
        alert("111");
        $('#adtype').on('change', function() {

            alert("aa");
                var lb = $('#adtype').val();
                if(lb = "seller")
                {
                    aler("1");
                    $('#seller').hide();
                    $('#buyer').show();

                }
                else
                {

                    $('#buyer').hide();
                    $('#seller').show();
                 }       
        });        
    </script>
 </head>

<p>
     {{ product_form.addtype.errors }}
     <label>Type of Ad:</label>
     <select name="ad"id="adtype">
    <option value="seller">Seller</option>
    <option value="buyer">Buyer</option>
   </select>
</p>

  <label id="seller"> Seller Information</label>
  <label id="buyer" style="display: none;"> Buyer Information</label>

以上标签想要改变。如果我点击卖家,我想改变labale作为卖家信息,反之亦然

1 个答案:

答案 0 :(得分:0)

作业始终评估为真:

if(lb = "seller")

尝试

if(lb == "seller")
相关问题