如何禁用文本区域? [英] How to disable a text area?
问题描述
如何禁用动态添加到HTML的文本区域?
How to disable a textarea which is dynamically added to the HTML?
HTML:
<div class="ss_datesel_inp_cont">
<div class="ss_datesel_inp_right_corner">
</div>
<input autocomplete="off">
</div>
这是我尝试过的:
$('.ss_datesel_inp_cont:textarea').prop("disabled", true);
$('.ss_datesel_inp_cont:input').prop("disabled", true);
推荐答案
在您发布的代码中没有看到textarea元素?根据您的标记,您可以通过以下方式禁用输入:
I don't see a textarea element in the code you posted? Based on the markup you have, you would disable the input by:
$('.ss_datesel_inp_cont input').prop('disabled', true);
您的代码无法运行的原因仅仅是因为选择器错误.输入是.ss_datesel_inp_cont
的后代,因此您需要使用.ss_datesel_inp_cont
和input
之间的空格来表示.输入也是直接子代,因此您也可以像$('.ss_datesel_inp_cont > input')
一样使用直接子代币>
.
The reason your code isn't working is simply because the selector is wrong. The input is a descendant of .ss_datesel_inp_cont
and therefore you need to indicate that with a space between .ss_datesel_inp_cont
and input
. The input is also a direct child, so alternatively you could use the direct child token >
as in $('.ss_datesel_inp_cont > input')
.
这篇关于如何禁用文本区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!