如何在樣式標記中使用javascript變量? 我試着用jQuery:如何在js中使用樣式標記中的變量
var height = $('.replyComment').height();
$('div.replyComment').append('<style>div.replyComment:before{content: ""; border-left: 1px solid #e1e1e1;position:absolute; left:38px; top:-20px; height:'+ height +';}</style>');
那麼我錯在哪裏?我需要做什麼來分配div的高度:在使用高度變量之前?
你可以使用'css()',應用css –
主要問題 - 你需要添加'px':height:'+ height +'px; ... etc ... css需要度量單位,jQuery height()返回數字。 – sinisake