HTML implements the unavailable state of the input box, and there are 2 methods to set the input box to be uneditable

This article mainly summarizes several methods for setting the text input box in the form element to be uneditable. There are generally 2 ways to make an input text box uneditable.

javascript set the input box is not editable method:

1. Use the disabled attribute setting

disabled

The attribute specifies that the input element should be disabled, and the disabled input element is neither usable nor clickable. The disabled property can be set until some other condition is met (such as a checkbox is selected, etc.). Then, it is necessary to pass

JavaScript to remove the disabled value and switch the value of the input element to available. disabled attribute cannot be used with

type="hidden"> is used together.

Set the input box to not be editable:

2. Use the readonly attribute setting

The readonly attribute specifies that the input field is read-only, and the read-only field cannot be modified. However, the user can still tab to the field and select or copy its text.

The readonly attribute prevents the user from modifying the value until certain conditions are met (such as a checkbox being checked). Then, you need to use JavaScript to eliminate the readonly value and switch the input field to an editable state.

The readonly attribute can be used with or .

Set the input box to not be editable:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324326605&siteId=291194637