简体   繁体   English

无法使用Angular.js / JavaScript通过jQuery序列化方法禁用下拉字段值

[英]Cannot get disabled drop down field values by jQuery serialize method using Angular.js/JavaScript

I need to fetch the selected data from the drop down list which is disabled using jQuery/Angular.js: 我需要从使用jQuery / Angular.js禁用的下拉列表中获取所选数据:

<div class="input-group bmargindiv1 col-md-12">
     <span class="input-group-addon ndrftextwidth text-right" style="width:180px">Status :</span>
    <select class="form-control" name="status"  id="status" ng-model="status"  ng-change="removeGSTValue('status');" disabled="disabled" >
                                     <option value="">Select Status</option>
     <option value="1">Active</option>
    <option value="0">Inavtive</option>
     </select>
    </div>

One value has already selected and this field is disable one can view it can not change. 已经选择了一个值,并且此字段已禁用,可以查看它不能更改。 I have to fetch the pre selected but it's not happening like that using jQuery serialize method. 我必须获取预先选择的内容,但使用jQuery序列化方法不会发生这种情况。 When I am using readonly the drop down value is changing. 当我使用只读时,下拉值正在更改。

You will want to use the readonly attribute and not disabled. 您将要使用readonly属性而不是禁用它。

You could do a bunch of workarounds like using a non disabled hidden field to pass a value to jQuery serialize but just use the right HTML attribute and you'll be fine. 您可以执行许多解决方法,例如使用非禁用的隐藏字段将值传递给jQuery序列化,但只需使用正确的HTML属性,就可以了。

Also, you don't need jQuery serialize. 另外,您不需要jQuery序列化。 Use a prefix to your ng-model like formData.status instead of status . 使用ng-model的前缀,例如formData.status而不是status Submit that formData value in your http request or just use JSON.stringify(formData) . 在您的http请求中提交该formData值,或仅使用JSON.stringify(formData)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM