Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将javascript函数转换为jQuery_Javascript_Jquery - Fatal编程技术网

将javascript函数转换为jQuery

将javascript函数转换为jQuery,javascript,jquery,Javascript,Jquery,如何将所选的javascript转换为jQuery?我需要选择按钮类而不是ID,我知道最简单的方法是jQuery var playButton1 = document.getElementById("playButton1"); playButton1.onclick = function() { var ta = document.getElementById("playButton1"); document['player'].receiveText1(ta.value)

如何将所选的javascript转换为jQuery?我需要选择按钮类而不是ID,我知道最简单的方法是jQuery

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

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

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

    ta.value = ""
};

尝试以下方法。您没有指定新的类名,所以我假设它是“playButton”

Play 1
第二场
$(函数(){
$(“.playButton”)。单击(函数(){
document['player'].receiveText1($(this.val());
});
});

你读过jQuery教程吗?问题出在哪里?有点离题,但为什么有变量
ta
?您不能直接使用
playButton1
变量吗?
var playButton1 = $("playButton1");

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

playButton1.onclick = function() {
    var ta = playButton1.val();
    document['player'].receiveText1(ta);
    playButton1.val('');
};
$(document).ready(function() {
  $('.playButton').click(function() {
    document['player'].receiveText1(this.value);
    this.value = "";
  });
});
$('#playButton1').click(function(){
    document['player'].receiveText1($('playerButton1').val());
    $('playerButton1').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 = ""
});