อยากทราบวฺิธีการทำปุ่มเพิ่มตัวเลย ครับ

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: อยากทราบวฺิธีการทำปุ่มเพิ่มตัวเลย ครับ

Re: อยากทราบวฺิธีการทำปุ่มเพิ่มตัวเลย ครับ

โดย jamepiyawat » 19/09/2019 6:44 pm

ทำได้แล้วผมใส่แท็กผิดครับพอดีว่าไปใส่ในแท็ก php ครับ :roll:

Re: อยากทราบวฺิธีการทำปุ่มเพิ่มตัวเลย ครับ

โดย tsukasaz » 19/09/2019 6:41 pm

อันนี้คือ javascript นะครับ ไม่ใช่ php ลองดูเรื่องการแทรก javascript หรือ css ใน joomla

Re: อยากทราบวฺิธีการทำปุ่มเพิ่มตัวเลย ครับ

โดย jamepiyawat » 19/09/2019 6:30 pm

เอาไปใสแล้วขึ้นว่า syntax error, unexpected '$', expecting variable (T_VARIABLE) ครับ

Re: อยากทราบวฺิธีการทำปุ่มเพิ่มตัวเลย ครับ

โดย tsukasaz » 19/09/2019 6:18 pm

หาไม่เจอก็เขียน javascript เพิ่มไปก็ได้ครับ

โค้ด: เลือกทั้งหมด

jQuery(function($) {
	$('.quantity-plus, .quantity-minus').click(function() {
		let value = parseInt($('.quantity-input').val());
		let new_value = $(this).hasClass('quantity-plus') ? value + 1 : value - 1;
		$('.quantity-input').val(new_value < 1 ? 1 : new_value);
	});
});

Re: อยากทราบวฺิธีการทำปุ่มเพิ่มตัวเลย ครับ

โดย jamepiyawat » 19/09/2019 5:00 pm

ต้องหายังไงเหรอครับ

Re: อยากทราบวฺิธีการทำปุ่มเพิ่มตัวเลย ครับ

โดย tsukasaz » 19/09/2019 11:02 am

น่าจะต้องใช้ javascript ทำ ลองดูของต้นฉบับที่ทำได้ ว่าใช้ javascript อะไร หาจากชื่อ class ก็ได้ quantity-plus quantity-minus

อยากทราบวฺิธีการทำปุ่มเพิ่มตัวเลย ครับ

โดย jamepiyawat » 19/09/2019 10:39 am

พอดีว่าผมได้ทำช่องที่จะใส่ตัวเลขลงไปแล้วอย่ากให้มีปุ่มที่จะให้ผู้ใช้สามารถคลิกแล้วเปลี่ยนตัวเลขได้เลยแต่ผมลองทำปุ่มที่ว่าออกมาแล้วแต่ว่ากดไม่ได้เป็นเพราะอะไรเหรอ ครับ
Selection_999(874).png
Selection_999(874).png (11.48 KiB) Viewed 1871 times
โค้ด

โค้ด: เลือกทั้งหมด

<span class="quantity-text">Quantity</span>
                                        <span class="quantity-box">
                                            <input type="text" class="quantity-input js-recalculate" name="quantity[]" data-errstr="You can buy this product only in multiples of %s pieces!" value="1" init="1" step="1">
                                        </span>

                                        <span class="quantity-controls js-recalculate">
                                            <button type="button" class="quantity-controls quantity-plus"><i class="fa fa-angle-up"></i></button>
                                            <button type="button" class="quantity-controls quantity-minus"><i class="fa fa-angle-down"></i></button>
                                        </span>

ข้างบน