当你点击HTML按钮时,你能更改HTML源代码吗

Can you change HTML source code when you click HTML button?

本文关键字:HTML 源代码 按钮 当你      更新时间:2023-09-26

当我单击HTML按钮时,源代码是否可能发生更改?

例如,如果HTML上有一行写着

  <p>The button was pressed <span id="displayCount">0</span> times.</p>

有可能把它改成吗

  <p>The button was pressed <span id="displayCount">1</span> times.</p>

当我阅读源代码或页面源代码时?

我正在使用Arduino发送一个HTTP请求,该请求将获得页面的HTML代码。因此,当我们查看页面源代码时,Arduino基本上得到了我们所看到的内容。这与"检查元素"时不同吗?

请在提出新问题之前进行搜索。

<button>click to up the count</button>
<p>The button was pressed <span id="displayCount">0</span> times.</p>
<script>
    $('button').click(function () {
        var newCount = parseInt($('#displayCount').text()) + 1;
        $('#displayCount').text(newCount);
    });
</script>

小提琴在这儿:http://jsfiddle.net/Fe5e5/

怎么样?

$("#button").click(function() {
  $("#displayCount").html(parseInt($("#displayCount").text()) + 1);
  return false;
});
$("input").click(function(){
    $("#displayCount").html("1");
});

使用jQueryhttp://api.jquery.com/click/

编辑:

如果你想做一个动态增量,按照其他人提供的方式进行:

 $("input").click(function(){
    var oldcount = parseInt($("#displayCount").html());
    $("#displayCount").html(oldcount++);
});

只需复制此代码

<script>
var count = 0;
function increment_Count(){
    count +=1;
    document.getElementById('displayCount').innerHTML=count;
}
</script>
<p>The button was pressed <span id="displayCount">0</span> times.</p>
<input type="button" onclick="increment_Count();" value="Click To Increment"/>