【问题标题】:SyntaxError: Failed to execute 'querySelector' on 'Document': '[object HTMLDocument]' is not a valid selectorSyntaxError:无法在“文档”上执行“querySelector”:“[object HTMLDocument]”不是有效的选择器
【发布时间】:2014-03-22 12:46:27
【问题描述】:

我正在尝试从显示模板上的共享点列表项中获取所有字段值,ctx.CurrentItem 仅获取一些值,但不是我需要的全部。

我尝试了以下代码,但我得到了标题上的错误

语法错误:无法在“文档”上执行“querySelector”:“[对象 HTMLDocument]' 不是有效的选择器。

function GetListItemById_Success(sender, args) 
{ 
   var id = ListItem.get_id(); 
   var title = ListItem.get_item("Title"); 
   alert("Updated List Item: \n Id: " + id + " \n Title: " + title); 
}

// Display an appropriate error message 
function GetListItemById_Fail(sender, args) 
{ 
   alert("GetListItemById Failed. \n" + args.get_message() + "\n" + args.get_stackTrace());
}

$(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(CustomAction, "sp.js"); });

function CustomAction(){
var clientContext =  new SP.ClientContext.get_current();
var web = clientContext .get_web(); 
var targetList = clientContext.get_web().get_lists().getByTitle('Test Document Library');
var list = web.get_lists().getByTitle('Test Document Library'); 
ListItem = list.getItemById(ctx.CurrentItem.DocId);
clientContext.load(ListItem, "Id", "Title"); 
clientContext.executeQueryAsync(GetListItemById_Success, GetListItemById_Fail); 
}

【问题讨论】:

    标签: javascript jquery sharepoint sharepoint-2010 csom


    【解决方案1】:

    升级位于顶级站点的 jQuery 后,我遇到了同样的异常。原因是在 subsite 母版页中引用了旧的 jQuery 库。

    【讨论】:

      猜你喜欢
      • 2020-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 1970-01-01
      • 2021-07-19
      相关资源
      最近更新 更多