TypeError: jQuery(…).ready(…) is not a function

Cập nhật lần cuối vào

Nếu bạn đang code WordPress và gặp phải thông báo lỗi TypeError: jQuery(…).ready(…) is not a function thì bạn có thể áp dụng cách chỉnh sửa như bài hướng dẫn này.

<script type="text/javascript">
	jQuery(document).ready(function($) {
		var client = new ZeroClipboard($('.copy-button'));
		client.on('ready', function(event) {
			client.on('copy', function(event) {
				var $element = $(event.target);
				event.clipboardData.setData('text/plain', $element.attr('data-clipboard-text'));
			});
			client.on('aftercopy', function(event) {
				var $element = $(event.target),
					$code = $element.prev(),
					out_url = $element.attr('data-out-url');
				$element.html('Copied');
				$element.addClass('disabled');
				$code.select();
				event.target.disabled = true;
			});
		});
		client.on('error', function(event) {
			ZeroClipboard.destroy();
		});
	})();
</script>

Trong đoạn code bên trên, khi bạn chạy trang web thì sẽ gặp thông báo lỗi TypeError: jQuery(…).ready(…) is not a function. Để giải quyết lỗi này thì bạn chỉ cần xóa mở ngoặc và đóng ngoặc ở cuối hàm là được.

<script type="text/javascript">
	jQuery(document).ready(function($) {
		// Your code here
	});
</script>

Dấu () chỉ để áp dụng cho các hàm thực thi ngay, nếu trong đoạn code của bạn có những hàm bạn muốn nó chạy cùng lúc trang web được tải thì bạn áp dụng kiểu này, còn sự kiện Query(document).ready không phải là một hàm. Chúc bạn thành công.

Theo dõi
Thông báo của
guest

0 Comments
Phản hồi nội tuyến
Xem tất cả bình luận