- user-select
- Синтаксис
- Формальный синтаксис
- Примеры
- HTML
- CSS
- Результат
- Спецификации
- Поддержка браузерами
- Смотрите также
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
- Html how to disable select jquery code example
- How do you enable or disable a select tag in html using jQuery?
- HTML how to disable select in text input field
- How to disable a select box without unchecking the selected option?
- How can I disable text selection on a jquery draggable?
- HTML/JavaScript — Disable Select Box
- Example syntax to disable a select box via HTML
- Example syntax to disable a multiple select box via HTML
- Compatibility
- IE
- W3.org
- «Try It» Source
- Public Domain
- user-select
- Try it
- Syntax
- Values
- Formal definition
- Formal syntax
user-select
Свойство CSS user-select определяет может ли пользователь выбрать текст. Оно не влияет на контент, загруженный как chrome, за исключением текстовых блоков.
/* Ключевые слова в значении */ user-select: none; user-select: auto; user-select: text; user-select: contain; user-select: all; /* Глобальные значения */ user-select: inherit; user-select: initial; user-select: unset; /* Специфичные для Mozilla значения */ -moz-user-select: none; -moz-user-select: text; -moz-user-select: all; /* Специфичные для WebKit значения */ -webkit-user-select: none; -webkit-user-select: text; -webkit-user-select: all; /*Не работает Safari; используйте только "none" или "text", или, в противном случае, оно будет разрешать ввод в контейнер */ /* Специфичные для Microsoft значения */ -ms-user-select: none; -ms-user-select: text; -ms-user-select: element;
Синтаксис
Текст элемента и вложенных в него элементов не выбирается. Обратите внимание, что объект Selection может содержать эти элементы.
Вычисляемое значение, автоматически определяется следующим образом:
- Для псевдо-элементов ::before и ::after вычисляемое значение — none
- Если элемент является редактируемым, вычисляемое значение — contain
- Иначе, если вычисляемое значение user-select для родителя этого элемента — all , вычисляемое значение — all
- Иначе, если вычисляемое значение user-select для родителя этого элемента — none , вычисляемое значение — none
- Иначе, вычисляемое значение — text
Текст может быть выбран пользователем.
В HTML-редакторе, если двойной клик или контекстный клик произошёл во вложенном элементе, будет выбрано все содержимое коренного предка с этим значением свойства.
Позволяет начать выбор внутри элемента; однако, выбор будет содержаться внутри границ данного элемента.
element Non-standard (IE-specific alias)
Аналогичен contain . Поддерживается только в Internet Explorer.
Формальный синтаксис
user-select =
auto | (en-US)
text | (en-US)
none | (en-US)
contain | (en-US)
all
Примеры
HTML
p>You should be able to select this text.p> p class="unselectable">Hey, you can't select this text!p> p class="all">Clicking once will select all of this text.p>
CSS
.unselectable -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; user-select: none; > .all -moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all; >
Результат
Спецификации
Поддержка браузерами
BCD tables only load in the browser
Смотрите также
Found a content problem with this page?
This page was last modified on 7 нояб. 2022 г. by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.
Html how to disable select jquery code example
Here’s one different to Matt’s based on Reid’s suggestion: The old jQuery attr method mixed up HTML attributes and DOM properties rather badly. JSFiddle Solution 1: this solution should work for you: Solution 2: use a as a parent of the input control and on click of this element-show the datepicker use disabled property on the input control: Solution 1: If you just want to prevent the user from modifying it, make it readonly instead of disabling it: UPDATE Now that you’ve clarified that your question has to do with copying the box, here’s a solution: FIDDLE When you just copy the HTML, all you get are the DOM elements.
How do you enable or disable a select tag in html using jQuery?
$("select[name='selectBRAVO']").attr('disabled', false);
The code also contains syntax errors. Fixes:
var $bravo = $("select[name='selectBRAVO']"); $("select[name='selectALPHA']").change(function () < $bravo.attr('enabled', !$bravo.attr('enabled')); >);
You seem to want to toggle the value, in plain js:
var select = document.getElementsByName('selectBRAVO')[0]; select.disabled = !select.disabled;
I’m sure you can figure out the jQuery equivalent.
Edit
Here’s one different to Matt’s based on Reid’s suggestion:
var select = $("select[name='selectBRAVO']")[0]; select.disabled = !select.disabled;
The old jQuery attr method mixed up HTML attributes and DOM properties rather badly. In the new version, attr deals only with HTML attributes, which is better. However, in the vast majority of cases, what programmers really want is the DOM property. That can be accessed directly, there is no need to call attr or getAttribute . Direct property access is (hugely) faster, less to type and easier to read.
I’m not so very sure what you are trying to achieve here but I think that this can help you :
$("select[name='select1']").change(function () < var jSelect2=$("select[name='select2']"); if($(this).val())< jSelect2.removeAttr('disabled'); >else < jSelect2.attr('disabled', 'disabled'); >>);
See working example here : JSFiddle
Disable with jquery Code Example, “disable
HTML how to disable select in text input field
this solution should work for you:
use a span/div as a parent of the input control and on click of this element-show the datepicker
use disabled property on the input control:
Jquery — How to disable a select box without unchecking, One way of doing it is to save current value in a temporary field / or in a temporary JS variable, and when you enable it, place it back. var t1 = »; //at disable t1 = document.getElementById (‘select_1’).value; //at enable document.getElementById (‘select_1’).value = t1; If you have multiple select …
How to disable a select box without unchecking the selected option?
If you just want to prevent the user from modifying it, make it readonly instead of disabling it:
$("#selectbox").attr('readonly', 'readonly')
Now that you’ve clarified that your question has to do with copying the select box, here’s a solution:
jQuery("select").change(function () < jQuery(this).attr("disabled", "disabled"); >); jQuery("button").click(function () < jQuery("select").removeAttr("disabled"); jQuery('.wrapper').append(jQuery('.select-wrapper:first select').clone(true).val(jQuery('.select-wrapper:first select').val())); >);
When you just copy the HTML, all you get are the DOM elements. Changes to input elements from user interaction is not included in the HTML. So this solution uses .clone() to copy the select element, and then copies the original select box’s current value to the clone.
Save the state and set it back:
$('#selectId').data('state', $('#selectId').val()).prop('disabled', true); //sowhere else in the code $('#selectId').prop('disabled', false).val($('#selectId').data('state'));
This way you don’t have to take care of variables.
One way of doing it is to save current value in a temporary field / or in a temporary JS variable, and when you enable it, place it back.
var t1 = ''; //at disable t1 = document.getElementById('select_1').value; //at enable document.getElementById('select_1').value = t1;
If you have multiple select boxes, you can save them in array:
Or, you can use a mask layer for each select box:
Set the width & height as per your visible size, and instead of DISABLE, just simple make this mask div display:inline . So when you want to ENABLE, make it display:none
You will also need to take care of div id to match the select box id for your ease.
How do you enable or disable a select tag in html using, var select = $(«select[name=’selectBRAVO’]»)[0]; select.disabled = !select.disabled; The old jQuery attr method mixed up HTML attributes and DOM properties rather badly. In the new version, attr deals only with HTML attributes, which is better. However, in the vast majority of cases, what programmers really …
How can I disable text selection on a jquery draggable?
Check this demo sources, for example:
edit
A post from jquery forum explaining the situation around disableSelection . Looks like it’s ‘undocumented’ for a long time already.
I know this post is ancient, but since I’ve found a possible solution I’ve decided to post it anyway. Simply add this line to your parent DIV (I know, ‘bind’ is depreciated. Sue me.):
$('#parentdiv').bind('mousedown', function(event) < event.preventDefault() >);
Selections don’t happen because mousedown events are never completed. I’ve tested this with multiple DIVs and it seems to work!
Jquery — HTML how to disable select in text input field, Show activity on this post. use a span/div as a parent of the input control and on click of this element-show the datepicker. use disabled property on the input control: . Share. Follow this answer to receive notifications. edited Feb 5, 2017 at 9:34. answered Feb 5, 2017 at 9:30. Mithilesh …
HTML/JavaScript — Disable Select Box
Sometimes it is necessary to prevent the user from changing the value of a select box. The HTML 4.0 specification defines the DISABLE attribute for the SELECT tag. This attribute can be accessed with the JavaScript disable read/write property.
Other Form elements also have the disable attribute/property. This includes BUTTON, INPUT, OPTGROUP, OPTION, SELECT, and TEXTAREA.
Example syntax to disable a select box via HTML
Example syntax to disable a multiple select box via HTML
Compatibility
2002-02-06 — The «Try It» example has been tested and works in Internet Explorer 5.0 and Netscape 6.1. It has been tested and does not work in Netscape 4.74. The disable attribute/property should work in any browser that supports HTML 4.0 and W3C DOM Level 1.
2004-09-27 — Tested again with newer browsers. Works in Firefox 1.0PR, Mozilla 1.7.3, Netscape 7.1, Opera 7.54, and IE 6.0.
IE
W3.org
«Try It» Source
Public Domain
The HTML and JavaScript listed below are released to the public domain. Read the Terms of Use for details. The contents of this page are still copyrighted.
Below is a full example of the «Try It» at the top of this page. It shows how to enable/disable a Select box dynamically with JavaScript. Included is a checkbox that uses the click event to enable/disable the select box.
user-select
The user-select CSS property controls whether the user can select text. This doesn’t have any effect on content loaded as part of a browser’s user interface (its chrome), except in textboxes.
Try it
Syntax
/* Keyword values */ user-select: none; user-select: auto; user-select: text; user-select: contain; user-select: all; /* Global values */ user-select: inherit; user-select: initial; user-select: revert; user-select: revert-layer; user-select: unset;
Note: user-select is not an inherited property, though the initial auto value makes it behave like it is inherited most of the time. WebKit/Chromium-based browsers do implement the property as inherited, which violates the behavior described in the spec, and this will bring some issues. Until now, Chromium has chosen to fix the issues to make the final behavior meet the specifications.
Values
The text of the element and its sub-elements is not selectable. Note that the Selection object can contain these elements.
The used value of auto is determined as follows:
- On the ::before and ::after pseudo elements, the used value is none
- If the element is an editable element, the used value is contain
- Otherwise, if the used value of user-select on the parent of this element is all , the used value is all
- Otherwise, if the used value of user-select on the parent of this element is none , the used value is none
- Otherwise, the used value is text
The text can be selected by the user.
The content of the element shall be selected atomically: If a selection would contain part of the element, then the selection must contain the entire element including all its descendants. If a double-click or context-click occurred in sub-elements, the highest ancestor with this value will be selected.
Enables selection to start within the element; however, the selection will be contained by the bounds of that element.
Note: CSS UI 4 renamed the element value to contain .