为什么style.height没有添加?

时间:2015-11-09 20:38:28

标签: javascript css

我有以下代码,它运行没有任何问题,但由于某种原因,高度永远不会设置。

function expandTextarea() {
    var textareas = document.getElementsByTagName('textarea');
    for (var i = 0; i < textareas.length; i++) {
        if (textareas[i].scrollHeight > 100) {
            textareas[i].style.height = textareas[i].scrollHeight + 'px !important';
        } else {
            textareas[i].style.height = '100px !important';
        }
    }
}

旧的完全相同的功能是,

jQuery('.disabled-textarea').each(function() {
    if(jQuery(this).prop('scrollHeight') > '100') {
        jQuery(this).attr('style', "height:" + jQuery(this).prop('scrollHeight') + "px !important");
    } else {
        jQuery(this).attr('style', "height: 100px !important");
    }
});

它没有任何问题。我只是想摆脱jQuery。

2 个答案:

答案 0 :(得分:4)

删除greylisting修复了它:

create view myview as
  select 'test' as testColumn
     , object_id
     , object_id * 1.5 as overtime_pay
  from sys.objects
  GO


declare @viewname varchar(100)='myview';
declare @columnname varchar(100)='overtime_pay';


WITH Details AS
(
    SELECT obj.name AS VIEW_NAME
          ,cols.name AS COLUMN_NAME
          ,vws.VIEW_DEFINITION
    FROM sys.columns AS cols 
    INNER JOIN sys.objects AS obj ON cols.object_id=obj.object_id
    INNER JOIN INFORMATION_SCHEMA.VIEWS AS vws ON vws.TABLE_NAME=obj.name 
    WHERE cols.name=@columnname 
     AND  obj.name=@viewname
     AND obj.type_desc='VIEW'
)
,SplittedOnCommaAndFrom AS
(
    SELECT *
          ,CAST('<x>' + REPLACE(REPLACE(VIEW_DEFINITION,',','</x><x>'),'from','</x><x>')+'</x>' AS XML) AsXml 
    FROM Details
)
SELECT VIEW_NAME 
      ,COLUMN_NAME
      ,The.ColumnLine.value('.','varchar(max)') AS COLUMN_DEFINITION
FROM SplittedOnCommaAndFrom 
CROSS APPLY AsXml.nodes('/x[contains(.,sql:column("COLUMN_NAME"))]') AS The(ColumnLine)
!important

答案 1 :(得分:0)

如果您需要yield尝试:

!important