我正在尝试从我的按钮显示值和data-value
。它没有显示任何东西。如果我不包含var cs var grade = $(this).val();
$(this).data("data-value");
<button type="button" data-toggle="modal" data-target="#myModal1" class="btn btn-warning btn-md" name="grade" value="<?php echo " $cs1"; ?>" data-value="CPS210-CompSci-I (4)">
<span class="glyphicon glyphicon-education "></span> Grade
</button>
<script>
$('button[name="grade"]').click(function() {
var grade = $(this).val();
var cs $(this).data("data-value");
if (grade == "") {
$('#grade').html("<h4> Fail or no grade received for "+cs+" " + grade + "</h4>");
} else {
$('#grade').html("<h4> Grade received for " +cs+" " + grade + "</h4>");
}
});
</script>
答案 0 :(得分:1)
var cs = $(this).attr("data-value");