我的尝试
HTML:
<button class="btn btn-info">7</button>
Jquery:
$(document).ready(() => {
$('button').click(() => {
console.log($(this));
console.log($(this).html());
console.log($(this).val());
});
});
期望的结果:
7
答案 0 :(得分:2)
您可以使用 .text() :
$(this).text()
$('button').on('click', function(e) {
console.log($(this).text());
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<button class="btn btn-info">7</button>