Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery-无法使用CSS动态更改textarea的高度!重要的_Javascript_Jquery - Fatal编程技术网

Javascript jQuery-无法使用CSS动态更改textarea的高度!重要的

Javascript jQuery-无法使用CSS动态更改textarea的高度!重要的,javascript,jquery,Javascript,Jquery,我正在尝试更改文本区域的高度。Zurb的基础已经定义了一个高度>代码> 5Rem!重要信息 现在,当我尝试使用jQuery更改我的高度时,它没有改变。我试过: $('textarea').height('500px') $('textarea').css('height', '500px', 'important); 什么都不管用。任何其他属性的CSS都会随着.CSS()而改变。我能做什么?如果5rem!重要信息设置为内联样式,则它具有最高优先级然后您不能用任何CSS规则覆盖它。然后,您必须更

我正在尝试更改文本区域的高度。Zurb的基础已经定义了一个高度>代码> 5Rem!重要信息

现在,当我尝试使用jQuery更改我的高度时,它没有改变。我试过:

$('textarea').height('500px')
$('textarea').css('height', '500px', 'important);

什么都不管用。任何其他属性的CSS都会随着
.CSS()
而改变。我能做什么?

如果
5rem!重要信息
设置为内联样式,则它具有最高优先级然后您不能用任何CSS规则覆盖它。然后,您必须更新内联样式。试试这个:

$('textarea').attr('style', 'height: 500px !important');
$('textarea').get(0).style.setProperty('height','200px','important');

CSSStyleDeclaration.setProperty()

没有回报。示例:styleObj.setProperty('color'、'red'、'important')

更新:

请看这个 你会在那里找到非常有用的信息

快乐编码

您可以使用css-但它不支持
优先级
字段

以下是正确的语法:

$('textarea').css('height','500px')
或者,如果需要
重要
,可以使用内联样式或类

:添加类

.areaHeight{
    height : 500px !important;
}

$('textarea').addClass('areaHeight')
还有其他不太可行的选择:试试这个

<textarea id="textareaid"> </textarea>
$('#textareaid').css('height', '500px');

$('#textareaid').css('height','500px');

尝试使用其中任何一种设置高度

Type:  1
 $("textareaid").height("600")

Type:  2
 $("textareaid").css("height","400px")

确保在创建dom元素后调用ur脚本

是已定义的样式
5rem!重要信息
内联样式?没有问题:您能检查一下其他样式定义是否覆盖了jQuery吗style@blunderboy,不,它是在基金会的css文件中定义的。
.css('height','500px','!important')-中缺少引号important@ShaunakD,不,您不需要
当您使用jQuery:
.css(名称、值、优先级)
时。好的,这很有效,谢谢!但是为什么我不能直接使用
.css()
?我不喜欢这样做,因为它会超越我的整个内联风格。欢迎使用SO!!我看这是一个新的答案。请尝试阅读现有答案和确切问题。你的回答没有回答OP的问题。