php
1<?php 2 3$sample = "123456789"; 4 5?>
html
1<html> 2 3 <button onclick="getData();">ボタン</button> 4 <div id="hoge" data-type="<?= $sample; ?>"></div> 5 6</html>
jquery
1<script> 2 3 function getdata() { 4 var test = $('#hoge'); 5 var val = test.data('type'); 6 console.log(val); 7 } 8 9</script>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/19 13:33
2019/05/19 13:35
2019/05/19 13:38
2019/05/19 13:49
2019/05/19 13:56 編集
2019/05/19 13:59
2019/05/19 14:08