我在我的HTML中有1个按钮和一些文本,如下所示:
function get_content(){
// I don't know how to do in here!!!
}
<input type="button" onclick="get_content()" value="Get Content"/>
<p id='txt'>
<span class="A">I am</span>
<span class="B">working in </span>
<span class="C">ABC company.</span>
</p>
Run Code Online (Sandbox Code Playgroud)
当用户单击该按钮时,该内容<p id='txt'>将成为以下内容
预期结果:
<p id='txt'>
// All the HTML element within the <p> will be disappear
I am working in ABC company.
</p>
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我如何编写javascript函数?谢谢.
<div id="hour" style="display: none">2</div>
Run Code Online (Sandbox Code Playgroud)
JavaScript代码:
<script type="text/javascript">
var _h = document.getElementById('hour').value
alert(_h);
</script>
Run Code Online (Sandbox Code Playgroud)
Chrome返回undefined.问题是什么?