質問編集履歴

2

HTMLコードの追加

2020/05/04 09:58

投稿

helloinf
helloinf

スコア1

test CHANGED
File without changes
test CHANGED
@@ -74,10 +74,120 @@
74
74
 
75
75
  ### 該当のソースコード
76
76
 
77
-
77
+ ```HTML
78
+
79
+ <div class="lng__table">
80
+
81
+ <div class="tab"><!-- btn -->
82
+
83
+ <div class="general_btn tab_btn"><img src="./common/img/general.jpg"></div>
84
+
85
+ <div class="hinge_support_btn tab_btn"><img src="./common/img/hinge_support.jpg"></div>
86
+
87
+ <div class="start" id="proStart"></div>
88
+
89
+ </div>
90
+
91
+ <div class="data">
92
+
93
+ <div class="general date_cont">
94
+
95
+ <h3></h3>
96
+
97
+ <div class="number">
98
+
99
+ <p class="row_desc"></p>
100
+
101
+ <input id="full_length" class="row_value" type="number" name="" value="0" min="0">
102
+
103
+ <select id="full_length_unit">
104
+
105
+ <option value="m">m</option>
106
+
107
+ <option value="km">km</option>
108
+
109
+ <option class="cm">cm</option>
110
+
111
+ <option value="mm">mm</option>
112
+
113
+ </select>
114
+
115
+ </div>
116
+
117
+ </div>
118
+
119
+ <div class="hinge_support date_cont">
120
+
121
+ <h3></h3>
122
+
123
+ <div class="number">
124
+
125
+ <p class="row_desc"></p>
126
+
127
+ <input id="hs_num" class="row_value" type="number" name="" value="0" min="0">
128
+
129
+ </div>
130
+
131
+ <div class="parts" id="hinge_support_parts"></div>
132
+
133
+ </div>
134
+
135
+ </div><!-- date -->
136
+
137
+ </div><!-- lng_table -->
138
+
139
+ ```
78
140
 
79
141
  ```JavaScripe
80
142
 
143
+ $(".hinge_support .number input").on('input', function(event) {
144
+
145
+ var codes = "";
146
+
147
+ for (var i=0; i < $(this).val(); i++) {
148
+
149
+ var code = '<div class="part part_'+ (i+1) +'">'
150
+
151
+ +'<p class="part_title">'+ (i+1) +'個目</p>'
152
+
153
+ +'<div class="position">'
154
+
155
+ +'<p class="row_desc">位置</p>'
156
+
157
+ +'<input id="hs_'+ (i+1) + '_posit" class="row_value" type="number" name="" id="" value="0" min="0">'
158
+
159
+ +'<select id="hs_'+ (i+1) + '_posit_unit">'
160
+
161
+ +'<option value="m">m</option>'
162
+
163
+ +'<option value="km">km</option>'
164
+
165
+ +'<option class="cm">cm</option>'
166
+
167
+ +'<option value="mm">mm</option>'
168
+
169
+ +'</select>'
170
+
171
+ +'</div>'
172
+
173
+ +'</div>';
174
+
175
+ codes = codes + code;
176
+
177
+ }
178
+
179
+ document.getElementById('hinge_support_parts').innerHTML = codes;
180
+
181
+ if ( $(this).val() == 0) {
182
+
183
+ document.getElementById('hinge_support_parts').innerHTML = " ";
184
+
185
+ }
186
+
187
+ });
188
+
189
+
190
+
81
191
  document.getElementById("proStart").onclick = function(){
82
192
 
83
193
  var full_length = unitChange($("#full_length").val(),$('#full_length_unit').val());

1

コードのソースの追加

2020/05/04 09:58

投稿

helloinf
helloinf

スコア1

test CHANGED
File without changes
test CHANGED
@@ -1,8 +1,4 @@
1
1
  ### 前提・実現したいこと
2
-
3
-
4
-
5
- ここに質問の内容を詳しく書いてください。
6
2
 
7
3
  JavaScriptで計算システムを作っています。
8
4
 
@@ -82,23 +78,79 @@
82
78
 
83
79
  ```JavaScripe
84
80
 
85
- for (var i = 0; i < hs[0] ;i++) {
81
+ document.getElementById("proStart").onclick = function(){
86
82
 
87
- var a = hs[i+1]["position"];
83
+ var full_length = unitChange($("#full_length").val(),$('#full_length_unit').val());
88
84
 
89
- var b = full_length;
90
85
 
91
- console.log(a);
92
86
 
93
- console.log(b);
87
+ var hs = [];
94
88
 
95
- console.log(a>b);
89
+ hs[0] = $("#hs_num").val();
96
90
 
97
- console.log(a<b);
91
+ i = 1;
98
92
 
99
- console.log(a===b);
93
+ for (var j = 0; j < hs[0]; j++) {
100
94
 
95
+ hs[i] = {};
96
+
97
+ hs[i]["position"] = unitChange($("#hs_"+ i + "_posit").val(),$("#hs_"+ i + "_posit_unit").val());
98
+
99
+ i++;
100
+
101
- }
101
+ }
102
+
103
+
104
+
105
+    for (var i = 0; i < hs[0] ;i++) {
106
+
107
+     var a = hs[i+1]["position"];
108
+
109
+     var b = full_length;
110
+
111
+     console.log(a);
112
+
113
+     console.log(b);
114
+
115
+     console.log(a>b);
116
+
117
+     console.log(a<b);
118
+
119
+     console.log(a===b);
120
+
121
+    }
122
+
123
+   };
124
+
125
+
126
+
127
+ function unitChange(value,unit) {
128
+
129
+ if(unit == "km") {
130
+
131
+ value /= 1000;
132
+
133
+ } else if(unit == "cm") {
134
+
135
+ value *= 100;
136
+
137
+ } else if(unit == "mm") {
138
+
139
+ value *= 1000;
140
+
141
+ }
142
+
143
+ if(unit == "kN") {
144
+
145
+ value /= 1000;
146
+
147
+ }
148
+
149
+ return value;
150
+
151
+ }
152
+
153
+
102
154
 
103
155
  ```
104
156