javascript显示按钮值

时间:2016-03-19 20:02:53

标签: javascript jquery

我正在尝试从我的按钮显示值和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>

1 个答案:

答案 0 :(得分:1)

var cs = $(this).attr("data-value");