使用Javascript添加内联样式 [英] Add inline style using Javascript

查看:875
本文介绍了使用Javascript添加内联样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将此代码添加到动态创建的div元素

I'm attempting to add this code to a dynamically created div element

style = "width:330px;float:left;" 

其中创建动态 div

var nFilter = document.createElement('div');
nFilter.className = 'well';
nFilter.innerHTML = '<label>' + sSearchStr + '</label>';

我的想法是添加 div class =well但我不知道我该怎么做。

My idea is to add the style after < div class="well" but i don't know how i'd do it.

推荐答案

nFilter.style.width='330px';
nFilter.style.float='left';

这应该为元素添加一个内联样式。

This should add an inline style to the element.

这篇关于使用Javascript添加内联样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆