如何使禁用/只读功能单选按钮和复选框

时间:2021-07-12 00:11:02

I know we can not make readonly to radio button and checkbox. I tried disabled to radio button and checkbox but in IE it is not clearly visible.

我知道我们不能只读取单选按钮和复选框。我尝试禁用单选按钮和复选框,但在IE中它不清晰可见。

Is any alternative to do same like disable/readonly using jQuery, CSS, JavaScript?

是否可以使用jQuery,CSS,JavaScript等禁用/ readonly?

4 个解决方案

#1


13  

You can use the following code to avoid clicks on elements you don't want user to change

您可以使用以下代码来避免点击您不希望用户更改的元素

$(':radio,:checkbox').click(function(){
    return false;
});

You can use proper selector to limit the clicks.

您可以使用适当的选择器来限制点击次数。

#2


7  

Yon can give like this:-

Yon可以这样给: -

i your script

我的脚本

 jQuery('#radio').attr('disabled','disabled');

Or you can addclass according to you..

或者你可以根据你添加类...

if it will not compatable with IE give compatibility also..

如果它不兼容IE也兼容..

<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />

then check..

you can also give like this:-

你也可以这样给: -

jQuery("#youridname input:radio").attr('disabled',true);

#3


3  

        selectedRow.find('input[type="radio"]:not(:checked)').each(function(){ $(this).attr('disabled', true); });

selected row is just the html element below which I want to locate the radio buttons i am interested.
the whole script is only called once a radio button has been selected.
when executed, it locates the unselected radio buttons and disables them.

选定的行只是html元素,我想在下面找到我感兴趣的单选按钮。只有在选择单选按钮后才会调用整个脚本。执行时,它会找到未选中的单选按钮并禁用它们。

hence, giving me the desired result of disabling the non-selected radio buttons, while maintaining the selected option.

因此,在保持所选选项的同时,给出了禁用未选中单选按钮的所需结果。

this result seemed to be a better option, then
1. laying an image over the radio button, to avoid the user from selected another option.
2. .click(function(){ return false; }), which just hides the selection when the unselected option is selected 3. disabling all the radio buttons, where the selection is lost.

这个结果似乎是一个更好的选择,然后1.在单选按钮上放置一个图像,以避免用户选择另一个选项。 2. .click(function(){return false;}),当选择了未选择的选项时,它只隐藏选择.3。禁用选择丢失的所有单选按钮。

hope this helps you,
cheers.

希望这对你有所帮助,干杯。

#4


1  

If radio button is already checked and if you click on checked radio button it change value from true to false. For this scenario following code works

如果已选中单选按钮,并且单击选中的单选按钮,则会将值从true更改为false。对于此方案,以下代码有效

$(document).ready(function () {
    $('input[type = "radio"]').change(function () {
        this.checked = false;
    });
});

#1


13  

You can use the following code to avoid clicks on elements you don't want user to change

您可以使用以下代码来避免点击您不希望用户更改的元素

$(':radio,:checkbox').click(function(){
    return false;
});

You can use proper selector to limit the clicks.

您可以使用适当的选择器来限制点击次数。

#2


7  

Yon can give like this:-

Yon可以这样给: -

i your script

我的脚本

 jQuery('#radio').attr('disabled','disabled');

Or you can addclass according to you..

或者你可以根据你添加类...

if it will not compatable with IE give compatibility also..

如果它不兼容IE也兼容..

<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />

then check..

you can also give like this:-

你也可以这样给: -

jQuery("#youridname input:radio").attr('disabled',true);

#3


3  

        selectedRow.find('input[type="radio"]:not(:checked)').each(function(){ $(this).attr('disabled', true); });

selected row is just the html element below which I want to locate the radio buttons i am interested.
the whole script is only called once a radio button has been selected.
when executed, it locates the unselected radio buttons and disables them.

选定的行只是html元素,我想在下面找到我感兴趣的单选按钮。只有在选择单选按钮后才会调用整个脚本。执行时,它会找到未选中的单选按钮并禁用它们。

hence, giving me the desired result of disabling the non-selected radio buttons, while maintaining the selected option.

因此,在保持所选选项的同时,给出了禁用未选中单选按钮的所需结果。

this result seemed to be a better option, then
1. laying an image over the radio button, to avoid the user from selected another option.
2. .click(function(){ return false; }), which just hides the selection when the unselected option is selected 3. disabling all the radio buttons, where the selection is lost.

这个结果似乎是一个更好的选择,然后1.在单选按钮上放置一个图像,以避免用户选择另一个选项。 2. .click(function(){return false;}),当选择了未选择的选项时,它只隐藏选择.3。禁用选择丢失的所有单选按钮。

hope this helps you,
cheers.

希望这对你有所帮助,干杯。

#4


1  

If radio button is already checked and if you click on checked radio button it change value from true to false. For this scenario following code works

如果已选中单选按钮,并且单击选中的单选按钮,则会将值从true更改为false。对于此方案,以下代码有效

$(document).ready(function () {
    $('input[type = "radio"]').change(function () {
        this.checked = false;
    });
});