【发布时间】:2012-12-04 12:59:50
【问题描述】:
我有一个包含单引号和双引号的字符串。 You can see here。首先,如果我尝试创建该字符串的 jquery 对象,我会破坏 href 和它的页面链接。这两个部分的行为类似于标签的属性,并在页面的链接部分附加了一个额外的双引号。像 $(mystr)= ... href="" display.aspx""" 的控制台,其中 display.aspx 是页面的链接。但是如果我尝试 href=\'display.aspx\',我就能得到预期输出。我如何摆脱这个属性分区问题?jsfiddle上给出的代码是
var s= "<tr role=\"row\" id=\"1\" tabindex=\"-1\" class=\"ui-widget-content jqgrow ui-row-ltr\"><td role=\"gridcell\" style=\"\" title=\"Albania\" aria-describedby=\"mytabl_Country\">Albania</td><td role=\"gridcell\" style=\"text-align:center;\" title=\"\" aria-describedby=\"mytabl_Nutrition related\"><img class=\"resultsGridImage\" src=\"Images/check.png\" oldtitle=\"Click on reference ID to view details:<ol><li>ID: <a target=\'_blank\' href=\"DisplayRefmat.aspx?NOPAID=241\">241</a>, Analyses of the situation and national action plan on food and nutrition for Albania 2003-2008</li> <li>ID: <a target=\'_blank\' href=\"DisplayRefmat.aspx?NOPAID=826\">826</a>, Towards a healthy country with healthy people - Public health and health promotion strategy</li> <li>ID: <a target=\'_blank\' href=\"DisplayRefmat.aspx?NOPAID=827\">827</a>, Analyses of the State of Food and Nutrition in Albania</li> <li>ID: <a target=\'_blank\' href=\"DisplayRefmat.aspx?NOPAID=828\">828</a>, Recommendation on healthy nutrition in Albania</li> </ol>\"></td></tr>";
console.debug($(s));
$('#btable').append(s);
【问题讨论】:
-
你想做什么,你在一个图像标签内打开一个有序列表(顺便不关闭图像标签),为什么?
-
结束双引号的字符串 > 即(\">";) 应该关闭图像标签。并且图像标签中包含插件所需的 oldtitle='orderedlist' 。它适用于其他浏览器,除了 9 和 ff 的最新版本。我需要停止分解 href 属性及其 url 值。
-
不是关闭的图片标签,用/like 关闭它,我看看能不能解决你的问题
-
img src 的标签正确地包含在从中检索此数据的表中。使用 $('thesourcetable').html() 获取数据后,它会丢失正斜杠 (/) 并仅显示双引号。我认为正则表达式可用于注入正斜杠。但这里的问题不是“我猜”,因为正确结束了 img src。我认为这个问题不需要使用 $(table).html() 来检索数据。需要找到其他方法来避免这个问题。感谢您的合作@DaniëlTulp。
-
抱歉,好像没找到解决办法,或许换个角度更好,换个方式来获得同样的功能?
标签: javascript jquery regex