Javascript 如何更改jquery对象的html

Javascript 如何更改jquery对象的html,javascript,jquery,Javascript,Jquery,在我的函数中,我调用的方法将$obj作为函数中的参数传递。我已经定义了currsel对象,现在在方法中,它显示给我的$obj.currsel.html()不是一个函数。我在下面分享我的代码 $(document).on('change','.ui-modulelist1',function(e){ var $targetSel =coreFrameWork.frModuleContId; var $thisVal= $(this).find("option:selected").

在我的函数中,我调用的方法将
$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){

                        }           

                });
        },
此参数必须是字符串。如果要从obj变量中获取动态url,请执行以下操作:

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

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

var $targetSel = $(coreFrameWork.frModuleContId);
这是:

var $targetSel =coreFrameWork.frModuleContId;
jQuery对象

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

我不知道该变量是什么,但您可以尝试将其包装到jQuery对象中:

var $targetSel = jQuery(coreFrameWork.frModuleContId);
此外,使用以$开头的名称来命名简单的js对象(这些名称通常用于命名代表jQuery对象的变量等)也不是一个好的做法

希望这对你有帮助

问候,


Marcelo

这是
coreFrameWork.frmodulencotid
是ID还是元素节点?是不是
var$targetSel=$('#'+coreFrameWork.frmodulencotid)
人们用
$
表示jQuery对象变量,这很正常,所以他们知道这个变量是jQuery对象<代码>变量$div=$('#myDiv')
var $targetSel = jQuery(coreFrameWork.frModuleContId);