我想通过单击按钮来更改元素的内容,然后将其返回到其原始消息。如果可能的话,我将如何使用切换类来做到这一点呢?
<doctype html>
<html>
<head>
<meta charset=utf-8>
<title>Day Practice</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"> </script>
</head>
<body>
<h1> HotDogs</h1>
<input type=button id=button value=button>
<script>
$("#button").click(function(){
$("h1").html("Change to this");
});
</script>
这会用一个按钮更改标题,但是当我再次单击该按钮时,我不知道如何还原它。也许切换课程,我不知道。
这应该解决:
$( "#button" ).toggle(function() {
$("h1").html("Change here");
}, function() {
$("h1").html("Revert back here");
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句