开发者

Convert javascript function to jQuery

开发者 https://www.devze.com 2023-04-07 09:04 出处:网络
Ho开发者_StackOverflow中文版w do I convert this javascript selected to jQuery?I need to select a button class rather than an ID, and I understand the easiest way to do this is jQuery.

Ho开发者_StackOverflow中文版w do I convert this javascript selected to jQuery? I need to select a button class rather than an ID, and I understand the easiest way to do this is jQuery.

var playButton1 = document.getElementById("playButton1");

playButton1.onclick = function() {
    var ta = document.getElementById("playButton1");

    document['player'].receiveText1(ta.value);

    ta.value = ""
};


Try the following. You didn't specify the new class name so I assumed it was "playButton".

$(document).ready(function() {
  $('.playButton').click(function() {
    document['player'].receiveText1(this.value);
    this.value = "";
  });
});


var playButton1 = $("#playButton1");

playButton1.onclick = function() {
    var ta = playButton1.val();
    document['player'].receiveText1(ta);
    playButton1.val('');
};


$('#playButton1').click(function(){
    document['player'].receiveText1($('playerButton1').val());
    $('playerButton1').val('');
});


var playButton1 = $("playButton1");

playButton1.click(function() {
    var ta = $("playButton1");
    document['player'].receiveText1(ta.val());
    ta.val("");
});


<button class="playButton" value="1">Play 1</button>
<button class="playButton" value="2">Play 2</button>
<script type="text/javascript">
    $(function(){
        $(".playButton").click(function(){
            document['player'].receiveText1($(this).val());
        });
    });
</script>


$('#Class').click(function(e){
    document['player'].receiveText1(event.target.value);
    event.target.value = ""
});
0

精彩评论

暂无评论...
验证码 换一张
取 消