クリックされたボタンを変更したい。初期状態では、「編集」ボタンは 1 つしかありません。クリックすると「保存」ボタンになり、その横に「キャンセル」ボタンも表示したいです。どうやってやるの?以下のコードがあります。
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>demo by roXon</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<button data-text="Save">Edit</button>
<p>Hello</p>
<p style="display: none">Good Bye</p>
<script>
$("button").click(function(){
$(this).nextUntil('button').toggle();
var btnText = $(this).text();
$(this).text( $(this).data('text') );
$(this).data('text', btnText );
});
</script>
</body>
</html>