如何将div文本转换为变量? [英] How to get the div text to a variable?
本文介绍了如何将div文本转换为变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hii,
我写了一个html代码,并且div包含soem文本.我需要从div中获取此文本.如何获取文本?请帮助.....
Hii ,
I have written an html code ,And a div contains soem text .I need to get this text from the div .How can i get the text ? Pls help .....
推荐答案
获取文本请尝试
To get the text try
var content = document.getElementById("MyDiv").innerText;
alert(content);
获取html使用
to get the html use
var content = document.getElementById("MyDiv").innerHTML;
alert(content);
这里MyDiv是div的ID
Here MyDiv is the id of the div
这篇关于如何将div文本转换为变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文