Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript获取DIV的innertext?_Javascript_Html - Fatal编程技术网

如何使用javascript获取DIV的innertext?

如何使用javascript获取DIV的innertext?,javascript,html,Javascript,Html,如何使用java脚本获取DIV控制器的内部文本?假设将DIV声明为: <div id="someDiv"> some content goes here </div> 简单的回答是: document.getElementById("id-of-div").innerText 考虑到您已经用asp.net-mvc-3标记了这个问题,很长的答案是这将在浏览器中运行,而不是在服务器(asp.net运行的服务器)上运行。在不发送请求的情况下,无法立即将内容从浏览器获取到

如何使用java脚本获取DIV控制器的内部文本?

假设将DIV声明为:

<div id="someDiv">
  some content goes here
</div>
简单的回答是:

document.getElementById("id-of-div").innerText

考虑到您已经用asp.net-mvc-3标记了这个问题,很长的答案是这将在浏览器中运行,而不是在服务器(asp.net运行的服务器)上运行。在不发送请求的情况下,无法立即将内容从浏览器获取到服务器。我猜您可能希望从页面对新的控制器操作进行ajax调用,但这取决于文本何时更改,以及您想对其执行什么操作。

查看前面回答的关于stackoverflow-->的问题innerText属性仅对块元素有效。根据定义,不同时具有开始标记和结束标记的元素不能具有innerText属性。不过,div是块元素。
document.getElementById("id-of-div").innerText