1

I am working in Django and populated the labels of the forms . Then I need one Field which is the "country" to be read only so that no one can edit that . I applied the following code but its not working . can some one help ?

jQuery12(".input_id_shipping_detail_country label").replaceWith("*Country");

This one is for replacing the label its working fine

<script>
jQuery1 = jQuery.noConflict();
jQuery1(window).load(function () {
    jQuery1("#id_billing_detail_country").val('Mexico');
}); 
</script>
{% else %}

<script>
jQuery1 = jQuery.noConflict();
jQuery1(window).load(function () {
    jQuery1("#id_billing_detail_country").val('United States');
}); 
</script>

This is for the default value load at onload function of window .

country(document).ready(function() 
{
    country('#id_billing_detail_country')
        .replaceWith(country('#id_billing_detail_country')
        .clone().attr('readonly', 'readonly'));
    country('#id_shipping_detail_country')
        .replaceWith(country('#id_shipping_detail_country')
        .clone().attr('readonly', 'readonly'));
    country("#id_billing_detail_country").css("border", "none");
    country("#id_shipping_detail_country").css("border", "none");

Now this is the code where I applied the read-only thing its not working . I have tried .prop instead of .attr as well.

4

2 回答 2

4

你想要做的是prop()这样使用:

$('.myselector').prop('readonly', true);

更改.myselector为您需要设置为只读的任何输入字段。

在这里它在 jsFiddle 中工作。

于 2013-05-29T13:00:17.937 回答
0

我在 window.load 上像这样使用它并且它有效。

   <script>
    jQuery12 = jQuery.noConflict();
    jQuery12(window).load(function () {
    jQuery12("#id_billing_detail_country").val('Mexico').attr('readonly', 'readonly');
    jQuery12("#id_shipping_detail_country").val('Mexico').attr('readonly', 'readonly');
    jQuery12('#id_same_billing_shipping').prop('checked', false);
    }); 
    </script>

谢谢大家

于 2013-05-29T13:21:46.610 回答