質問するログイン新規登録

質問編集履歴

2

修正

2017/04/20 15:18

投稿

kotori_00
kotori_00

スコア46

title CHANGED
@@ -1,1 +1,1 @@
1
- 文字列と文字列の比較
1
+ ifでの文字列と文字列の比較
body CHANGED
File without changes

1

修正

2017/04/20 15:18

投稿

kotori_00
kotori_00

スコア46

title CHANGED
File without changes
body CHANGED
@@ -2,7 +2,7 @@
2
2
  jQueryのclickイベントを使用して、文字列と文字列をif文の条件式で比較して動作させたいです。
3
3
  動作内容は、
4
4
  - input[type="button"]のvalueを変更
5
- - ある要素を表示、非表示する
5
+ - p要素を表示、非表示する
6
6
 
7
7
  です。
8
8
 
@@ -10,13 +10,29 @@
10
10
  #コード
11
11
 
12
12
  ```html
13
-
14
13
  <p class="show">sample</p>
15
- <p class="hidden">sample-hidden</p>
14
+ <p class="hidden">sample-hidden</p>
16
- <label for="">〒&nbsp;<input type="text" size="6" maxlength="3">&nbsp;-&nbsp;<input type="text" size="8" maxlength="4">&nbsp;<input class="post-btn" type="button" value="ボタン"></label>
15
+ <input class="btn" type="button" value="ボタン">
17
16
 
18
- <p class="show">sample</p>
19
- <p class="hidden"></p>
20
- <label for="">
21
- </label>
22
- ```
17
+ ```
18
+
19
+ ```jQuery
20
+ $(function(){
21
+ $('.btn').click(function(){
22
+ var $btn = $(this).val();
23
+ var $btnButton = $(this).val('ボタン');
24
+ if($btn.equals($btnButton)){
25
+ $(this).val('ok');
26
+ $('.show').hide();
27
+ $('.hidden').show();
28
+ alert('true');
29
+ } else {
30
+ $btnButton;
31
+ $('.show').show();
32
+ $('.hidden').hide();
33
+ alert('faluse');
34
+ });
35
+ });
36
+ ```
37
+ ちなみに、ボタンをクリックしてもalert();がどちらも動作しませんでした。
38
+ それと、オブジェクト$('.btn')を$('input[type="button"]')にしても同じでした。