<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
<div align="center" style="margin-top:15%;">
<div id="out" align="center" style="border-style:solid;border-width:1px;width:300px;">
<div id="out_text" align="center" style="margin-top:20;height:40px;width:200px;">
Welcome
</div>
<form method="post">
Username: <input type="text" name="user"><br>
Password: <input type="password" name="password"><br>
<input id="login" type="submit" value="Login">
<input id="add" type="submit" value="Add User">
</form>
</div>
<div id="in" style="border-style:solid;border-width:1px;width:300px;">
<div id="in_text" align="center" style="margin-top:20;height:40px;width:200px;">
"test"
</div>
<form>
<input id="logout" type="submit" id="logout" value="Logout">
</form>
</div>
</div>
<script>
$(document).ready(function() {
$('#out').show();
$('#in').hide();
});
$('#login').click(function() {
$('#out').hide();
$('#in').show();
$('#in_text').text("Success");
});
$('#logout').click(function() {
$('#out').show();
$('#in').hide();
$('#out_text').text("Welcome");
});
</script>
</body>
</html>
私の質問は、ページの読み込みが終了したときに、なぜ $(document).ready が id="in" で div を非表示にしないのですか? その通りだと思いました。私はここで何かを逃していますか?さまざまなチュートリアルを見てみると、私がやっているのと同じことをしているのがわかりますが、何らかの理由で私のjqueryが機能していません。
編集:わかりました。皆さんのおかげで、他のdivを非表示にすることができました。ありがとうございました。しかし、今私は別の問題を抱えています。どの div を表示してテキストを変更するかを切り替える onclick イベント ハンドラを作成しようとしています。私は次のようにコードを編集しました。