当你点击HTML按钮时,你能更改HTML源代码吗
Can you change HTML source code when you click HTML button?
当我单击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"/>
相关文章:
- 在不更改HTML源代码的情况下,在管理员TinyMCE编辑器中突出显示文本
- 如何在HTML源代码中提取javascript变量
- 如何在internjs中打印createpage中的HTML源代码
- 客户端 JavaScript 没有定义 - 但它在 HTML 源代码中.任何人都知道为什么
- VB.NET-WebBrowser没有't在html源代码中显示javascript创建的html元素
- 如何在PhantomJS中使用iframes获得完整的解释html源代码
- jQuery验证后,$.ajax返回HTML源代码
- 如何从 URL HTML 源代码中获取特定信息
- 如何在不获取整个源代码的情况下解析 HTML 源代码
- jQuery更改元素属性并返回编辑后的Html源代码
- 从 html 源代码中删除 vbscript 或停用 vbscript
- 我可以使用Jquery获取元素的HTML源代码吗?
- 如果某些内容在 HTML 源代码中,则重定向到另一个页面的脚本
- 获取格式正确的 html 源代码
- html 源代码中缺少“”
- 从动态页面中提取 html 源代码
- 使用javascript获取html源代码,包括样式
- 如何在 Java 中执行页面上的 Javascript 后访问更新的 HTML 源代码
- Linux 上的 Phantomjs 返回空的 HTML 源代码
- 动态加载的元素不在 HTML 源代码中