如何使用jquery或javascript将css类添加到文本框中

How do I add a css class to the text box using jquery or javascript?

本文关键字:添加 文本 css jquery 何使用 javascript      更新时间:2023-09-26

我需要在这个文本框中添加一个类。

$(document).ready(function() {
    $('.text-element').on('click', function(event){
        var textBox = document.createElement('input');
        textBox.type = 'text';
        document.getElementById('titlebox').appendChild(textBox);
    });
});

有些人喜欢

textBox.className = 'some-name';

您可以使用jQuery将类添加到元素中。例如:

$(textBox).addClass('box-element');