clickイベントを作成したいと思います。Clickイベントoop
ただし、controlCount()のconsole.logの値は異なります。
function Spinbox() {
this.MIN_COUNT = 180;
this.MAX_COUNT = 220;
this.$inputBox = $(`<input type="text"/>`);
this.$increaseButton = $(`<button type="button">+</button>`);
this.$decreaseButton = $(`<button type="button">-</button>`);
}
Spinbox.prototype.controlCount = function() {
console.log(this.$inputBox.val());
// not working. because this = <button type="button">+</button>
}
Spinbox.prototype.create = function() {
this.$increaseButton.click(this.controlCount);
$("#wrap").append(this.$inputBox);
$("#wrap").append(this.$increaseButton);
$("#wrap").append(this.$decreaseButton);
}
var spinbox1 = new Spinbox();
spinbox1.create();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrap">
</div>
なぜあなたはボタンの 'val'を取得しようとしていますか?ボタンの 'text'を使いますか? 'this。$ increaseButton.text()'?それはちょうどあなたに+シンボルを与えます。 – TKoL
申し訳ありませんが、mymistake。私の質問を変更します –