jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了javascript – jQuery val是未定义的?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个代码
<input type="hidden" id="editortitle" name="title" value="home">
<textarea name="text" id="editorText"></textarea>

但是当我写$(‘#editortitle’).val()和$(‘#editorText’).html(),$(‘#editortitle’).val()是’undefined’和$(‘#editorText’ ).html()是空的?

哪里不对?

编辑:

这是我的完整代码

function openEditor() {
    $("#editor").show().animate({ width: 965,height: 380 },1500);
    $("#editor textarea").show();
}

function closeEditor() {
    $("#editor").animate({ width: 985,height: 1 },1500,function () {
        $("#editor").hide();
        $("#editor textarea").hide();
    });
}

function setedit() {
    $.ajax({
        type: "POST",url: "ENGIne.PHP",data: "title=" + $('#editortitle').attr('value') + "&text=" + $('#editorText').html(),beforeSend: function () {
            $('#mainField').html('<img src="data/images/loader.gif" alt="Loading...">');
        },success: function (msg) {
            alert(msg);
            closeEditor();
            search();
        }
    });
}
function search() {
    $('#title').val($('#search').val());

    $.get('ENGIne.PHP?search=' + $('#search').val(),function (data) {
        $('#mainField').html(data);
    });

    $.get('ENGIne.PHP?raw=true&search=' + $('#search').val(),function (data2) {
        $('#editorText').html(data2);
    });

    $.get('ENGIne.PHP?title=true&search=' + $('#search').val(),function (data2) {
        $('#h1').html(data2); // Row 152
        $('#editortitle').html(data2);
    });
}

$(document).ready(function () {
    $("#ready").html('Document ready at ' + event.timestamp);
});

但是怎么了?

解决方法

您可能在HTML: example之前包含您的JavaScript.

您应该在窗口加载时执行JavaScript(或者更好地,当DOM完全加载时),或者应该在HTML之后包含JavaScript:example.

大佬总结

以上是大佬教程为你收集整理的javascript – jQuery val是未定义的?全部内容,希望文章能够帮你解决javascript – jQuery val是未定义的?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。