将一个JavaScript字符串转换为一个html对象 [英] converting a javascript string to a html object
问题描述
我可以将字符串转换为html对象吗?
like:
string s ='< div id =myDiv>< / div>' ;
var htmlObject = s.toHtmlObject;
这样我就可以稍后通过id获取它并改变它的风格
var ho = document.getElementById(myDiv)。style.marginTop = something;
提前一万美元,
Lina
<$> p $ p>
string s ='< div id =myDiv>< / div>'
var htmlObject = $(s); // jquery call
但仍然不会被 getElementById找到
因为要工作,元素必须在DOM中......只是在内存中创建不会插入到DOM中。
您需要在之后使用 Of'course所有这些都可以通过常规的javascript来完成,但是需要更多的步骤来完成同样的事情。 。这两种情况下的逻辑都是一样的。 can I convert a string to a html object?
like: so that i can later on get it by id and do some changing in its style Thanx a million in advance,
Lina You cannot do it with just method, unless you use some javascript framework like jquery which supports it .. but still, it would not be found by the You would need to use Of'course all these can be done through regular javascript but it would take more steps to accomplish the same thing... and the logic is the same in both cases.. 这篇关于将一个JavaScript字符串转换为一个html对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! append
或 appendTo
或>等..首先把它放在dom中。
string s = '<div id="myDiv"></div>';
var htmlObject = s.toHtmlObject;
var ho = document.getElementById("myDiv").style.marginTop = something;
string s = '<div id="myDiv"></div>'
var htmlObject = $(s); // jquery call
getElementById
because for that to work the element must be in the DOM... just creating in the memory does not insert it in the dom.append
or appendTo
or after
etc.. to put it in the dom first..