js简单的获取与输出

js获取标签内容和输出内容到页面

获取:

html: 

<select id="choiceSelect" onchange="changeImg()">
  <option value="1">石头</option>
   <option value="2">剪刀</option>
   <option value="3"></option>
</select>
<img src="img/1.png" id="img1">

js:

<script type="text/javascript">
        var n1 = 1;function changeImg(){
            var changeImg = document.getElementById("choiceSelect");
            n1 = changeImg.value;
            // alert(n1);
            document.getElementById("img1").src="img/"+n1+".png";
        }</script>

输出:

html: <p id = "finalresult"></p>

js: document.getElementById("finalresult").innerHTML = "输出的内容";

猜你喜欢

转载自www.cnblogs.com/makangning/p/9373948.html
今日推荐