如何更改jquery对象的html

How to change html of a jquery object

本文关键字:html 对象 jquery 何更改      更新时间:2023-09-26

在我的函数中,我调用将$obj作为函数中的参数传递的方法。我已经定义了currsel对象,现在在方法中,它向我显示$obj.currsel.html()不是一个函数。我在下面分享我的代码。

$(document).on('change','.ui-modulelist1',function(e){
    var $targetSel =coreFrameWork.frModuleContId;
    var $thisVal= $(this).find("option:selected").val();
    var loadUrl = '../ux_framework_New/_'+$thisVal+'/index.html';
    commonFramework.initLoad({'url':loadUrl, 'currSel':$targetSel, 'mode':'autoload'});
            });
var commonFramework ={
    initLoad:function($obj){
                $.ajax({
                        type: "GET",
                        url: $obj.url,
                        dataType: "html",
                        cache:false,
                        async:false,
                        beforeSend: function(xhr){
                            xhr.withCredentials = false;
                        },
                        success: function(html) {
                            $obj.currSel.html(html);
                            $obj.currSel.attr(projCommonAttr.autoloadAttr,'loaded');
                        commonFramework.contentSpecific({'currSel':$obj.currSel,'mode':$obj.mode});
                        },
                        error: function(qXHR, textStatus, errorThrown){
                        }           
                });
        },

如果没有看到一个示例url,很难判断。什么是coreFrameWork.frModuleContId?请尝试将其记录在控制台中。我猜你需要做

var $targetSel = $(coreFrameWork.frModuleContId);

这是吗

var $targetSel =coreFrameWork.frModuleContId;

jQuery对象?

函数html()属于jQuery,所以如果您的对象不是jQuery对象,它将找不到该方法。

我不知道这个变量是什么,但你可以试着把它包装成一个jQuery对象:

var $targetSel = jQuery(coreFrameWork.frModuleContId);

此外,使用以$开头的名称来命名简单的js对象并不是一个好的做法(这些名称通常用于命名表示jQuery对象的变量)。

希望这对你有帮助。

问候,

Marcelo

url: $obj.url,

此参数必须是字符串。如果你想要一个动态url从你的obj变量这样做:

url: $obj+".php", // .php or whatever the file type is of the page you're requesting