Hiển thị các bài đăng có nhãn Nhập Input Text Js. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Nhập Input Text Js. Hiển thị tất cả bài đăng

Thứ Sáu, 16 tháng 1, 2026

Nhập Input Text Js

 Nhập Input Text trên thì Input Text dưới hiện y chang

**** Cách 1:

<input name="title" id="title" type="text" class="form-control" value="Máy pha cà phê Solis Barista Perfetta Plus">

<input name="pid_link" id="pid_link"  type="text" class="form-control" value="May-pha-ca-phe-Solis-Barista-Perfetta-Plus">

<script>

$(document).ready(function ($) {

    function slugify(text) {

        return text

            .toLowerCase()

            .normalize('NFD')

            .replace(/[\u0300-\u036f]/g, '')

            .replace(/[^a-z0-9\s-]/g, '')

            .trim()

            .replace(/\s+/g, '-')

            .replace(/-+/g, '-');

    }

    function autoSlug(titleSelector, slugSelector) {

        $(document).on('input blur change', titleSelector, function () {

            $(slugSelector).val(slugify($(this).val()));

        });

    }

    // dùng

    autoSlug('#title', '#pid_link');

});

</script>

#---------------------------------#

Cách 2:

<input class="form-control js-slug-title" data-slug="#pid_link">

<input id="pid_link" class="form-control">

<script>

$(document).ready(function ($) {

    function slugify(text) {

        return text

            .toLowerCase()

            // xử lý đ

            .replace(/đ/g, 'd')

            .replace(/Đ/g, 'd')

            // bỏ dấu tiếng Việt

            .normalize('NFD')

            .replace(/[\u0300-\u036f]/g, '')

            // xóa ký tự đặc biệt

            .replace(/[^a-z0-9\s-]/g, '')

            // trim

            .trim()

            // space -> -

            .replace(/\s+/g, '-')

            // -- -> -

            .replace(/-+/g, '-');

    }

    $(document).on('input', '.js-slug-title', function () {

        const target = $(this).data('slug');

        $(target).val(slugify($(this).val()));

    });

});

</script>