2つのボタンがあります。いずれかのボタンをクリックすると、クリックしたボタンが表示されます。しかし、私のコードは動作していません。ボタンをクリックすると、ボタンのそれぞれのIDが表示されます。私は間違いがどこにあるのか分からなかった。ありがとうございました。jquery on click機能が表示されない
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn").click(function(){
var qn=$(this).attr("id");
("#two").html.("you clicked on button"+qn);
});
});
</script>
<style>
#one
{
width:100%;
height:70px;
background-color:green;
clear:both;
}
#two
{
width:75%;
height:250px;
overflow-y:scroll;
float:left;
}
#three
{
width:24.5%;
height:50px;
float:right;
float:right;
}
.btn
{
width:45px;
height:45px;
align-text:center;
}
</style>
</head>
<body>
<div id="one"></div>
<div id="two"></div>
<div id="three">
<?php
$i=1;
for($i=1;$i<3;$i++)
{
echo"<button class='btn' id='$i' value='$i'>$i</button>";
}
?>
</div>
</body>
あなたのボタンがクラス.btnを持っていない:
それはここではフィドルだ
でなければなりません。 jQueryのセレクタは何も返しません – user3154108
あなたは型エラー '(" #two ")html。()' $( "#two")でなければなりませんhtml() ' –
時には小さなミスが大きな頭痛につながることがあります。その働きのおかげで多くは – PAVAN