HTML属性是否可以包含撇号

时间:2011-11-10 05:19:03

标签: jquery jquery-selectors html-parsing html

由于多种原因,我最终得到了一些需要在HTML属性标记内存储JSON序列化对象的代码。

然而,我遇到了一个问题,我的一个json序列化对象包含一个撇号,结果似乎破坏了jQuery。

基本上这就是行为......

以下是表格标题定义。

<table class='DraggableRowTable' RowData='{"AuthorID":"652c90e4-ffef-49c5-9217-0ff39a461011","Created":"\/Date(1319429903223+1100)\/","EditorID":"652c90e4-ffef-49c5-9217-0ff39a461011","Modified":"\/Date(1319429903223+1100)\/","AssignedToID":"7daef058-d84c-43f5-9db1-8011c59673ee","DetailedTaskID":"169ea939-7cb7-4599-9c2a-9e8ef4dee641","Duration":4.0000,"EndDate":"\/Date(1319497200000+1100)\/","ManualCalculation":false,"RoleID":"944f0ea3-4312-4f14-9d00-c968a647996a","Sequence":14,"StartDate":"\/Date(1319429872333+1100)\/","Status":0,"SubSequence":0,"Task":{"AuthorID":"652c90e4-ffef-49c5-9217-0ff39a461011","Created":"\/Date(1319172394650+1100)\/","EditorID":"652c90e4-ffef-49c5-9217-0ff39a461011","Modified":"\/Date(1319172394650+1100)\/","AssignedToID":"7daef058-d84c-43f5-9db1-8011c59673ee","Duration":4,"IsActive":true,"ProductID":"dad82b06-7d28-4255-bf02-f709eeed64cd","RoleID":"944f0ea3-4312-4f14-9d00-c968a647996a","Sequence":14,"TaskDescription":"es reviewer is to review the following fields and provide feedback to the writer if they' need fixing:\u000d\u000a*description\u000d\u000a*key learning objectives\u000d\u000a*educational value statements","TaskID":"6f577537-ce4a-46cd-9eb6-29bd5756ab26","TaskName":"educational soundness review"},"TaskID":"6f577537-ce4a-46cd-9eb6-29bd5756ab26","WorkOrder":{"AuthorID":"652c90e4-ffef-49c5-9217-0ff39a461011","Created":"\/Date(1319429872333+1100)\/","EditorID":"652c90e4-ffef-49c5-9217-0ff39a461011","Modified":"\/Date(1319429872333+1100)\/","IsActive":true,"Priority":1,"ProductID":"dad82b06-7d28-4255-bf02-f709eeed64cd","Qty":1,"StartDate":"\/Date(1319429872333+1100)\/","Status":0,"Subtitle":null,"WorkOrderDescription":null,"WorkOrderExternalID":43,"WorkOrderID":"66c40ff8-56e1-4009-89ab-989b0e25d120","WorkOrderName":"Work order #43"},"WorkOrderID":"66c40ff8-56e1-4009-89ab-989b0e25d120"}'>

以下是代码。

var Data = $(GridRow).find(".DraggableRowTable").attr("RowData");
//Data = "{"AuthorID":"652c90e4-ffef-49c5-9217-0ff39a461011","Created":"\/Date(1319429903223+1100)\/","EditorID":"652c90e4-ffef-49c5-9217-0ff39a461011","Modified":"\/Date(1319429903223+1100)\/","AssignedToID":"7daef058-d84c-43f5-9db1-8011c59673ee","DetailedTaskID":"169ea939-7cb7-4599-9c2a-9e8ef4dee641","Duration":4.0000,"EndDate":"\/Date(1319497200000+1100)\/","ManualCalculation":false,"RoleID":"944f0ea3-4312-4f14-9d00-c968a647996a","Sequence":14,"StartDate":"\/Date(1319429872333+1100)\/","Status":0,"SubSequence":0,"Task":{"AuthorID":"652c90e4-ffef-49c5-9217-0ff39a461011","Created":"\/Date(1319172394650+1100)\/","EditorID":"652c90e4-ffef-49c5-9217-0ff39a461011","Modified":"\/Date(1319172394650+1100)\/","AssignedToID":"7daef058-d84c-43f5-9db1-8011c59673ee","Duration":4,"IsActive":true,"ProductID":"dad82b06-7d28-4255-bf02-f709eeed64cd","RoleID":"944f0ea3-4312-4f14-9d00-c968a647996a","Sequence":14,"TaskDescription":"es reviewer is to review the following fields and provide feedback to the writer if they" //As you can see, it all breaks here...

所以我想我想知道,首先在HTML属性中有撇号是有效的(IE:HTML标准是否支持这个),其次(取决于第一个的答案)jQuery是否应该能够正确返回这个属性?

1 个答案:

答案 0 :(得分:4)

您没有说出哪个版本的HTML,所以我会假设HTML5

  

除非另有说明,否则HTML元素的属性可能包含任何字符串值,包括空字符串。除非明确说明,否则对此类属性中可指定的文本没有限制。

你的问题是你没有编纂叛逆。您可能需要将'的出现次数更改为&apos;。你真的应该对整个字符串进行HTML编码。