jquery空无法工作

ben*_*e89 2 jquery input

任何人都明白为什么这不会按预期工作!?

$('.project_ref_input').val().empty();
Run Code Online (Sandbox Code Playgroud)

我试过.text()和.empty()...没有运气!?

.project_ref_input是输入的类

这是完整的jquery代码:

$('.project_ref_input').live('change',function(){ 
                var project_ref_input=$(this).val();
                $(this).next().replaceWith("<p>" + project_ref_input + "</p>");
                $('.project_ref_input').val().empty();
            });
Run Code Online (Sandbox Code Playgroud)

Kob*_*obi 5

它不起作用,因为val不返回jQuery对象,而是返回一个字符串.要设置值,请将其val作为参数传递给它.尝试:

$('.project_ref_input').val('');
Run Code Online (Sandbox Code Playgroud)