2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

jQuery 備忘録

Posted at

・js側で値の受け渡し方法

index.html
<form id="modal-form">
 <input type="hidden" id="modal-value-1" /> //値を入れたいhidden
</form>
<input type="text" id="modal-input-1" name="data[User][name]" /> //値を受け取るinput
index.js
var inputVal = $("#̲modal-input-1").val(); //一度変数に受ける
$("#modal-value-1").val(inputVal);

data属性を使って値を設定すれば、あらゆることに利用できる。

form.html
<button class="add mon" data-daynum="1">
<button class="add tue" data-daynum="2">
<button class="add wed" data-daynum="3">
.....
form.js
$(document).on("click", "クラス名", function(){
 let daynum = $(this).attr("data-daynum"); //daynumに曜日番号が入る
 以下いろいろな処理
});
2
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?