码迷,mamicode.com
首页 > Web开发 > 详细

js之获取html标签的值

时间:2018-09-28 01:37:48      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:OLE   button   script   world   html   type   onclick   console   fun   

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>
<div>
    <input id=‘user‘ type=‘text‘  />
    //绑定getData函数
    <input   type="button"  value="提交" onclick="getData();"/>
    <div id="i1">helloworld</div>

</div>


</body>

<script>
    function getData() {
        //获取输入框的文本
        var i=document.getElementById(‘user‘);
        alert(i.value);
        console.log(i.value)
    
    }

    //获取div的文本内容
    var tag=document.getElementById(‘i1‘)
    var content=tag.innerText
    
        console.log(content)



</script>
</html>

  

js之获取html标签的值

标签:OLE   button   script   world   html   type   onclick   console   fun   

原文地址:https://www.cnblogs.com/randomlee/p/9716409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!