编辑:这不是因为 ajax 调用而发生的。为了好玩,我将其更改为使用来自 TinyMCE 组件的值,我得到了同样的结果。
content = tinyMCE.get('cComponent').getContent(); //content at this point is <p>test</p>
valueToDisplay = content;
如果我这样做:
jQuery(selector).html(valueToDisplay);
我得到:
<p><a xmlns="http://www.w3.org/1999/xhtml">test</a></p>
有没有人在使用 Firefox 3.6.10 和 jQuery 1.4.2 之前见过这个,我正在尝试使用 jQuery ajax 调用的结果更改链接文本。
我得到了 ajax 调用的预期结果:
function getValueToDisplay(fieldType){
var returnValue;
jQuery.ajax({
type: "GET",
url: "index.cfm",
async:false,
data: "fieldtype="+fieldType,
success:function(response){
returnValue = response;
}
});
return returnValue;
}
如果我此时检查值,我会得到预期值
console.log(returnValue) //output this --> <p>Passport Photo</p>
但是,当我使用 jQuery(selector).html 将其插入到现有 anchor 中时
我得到:
<p><a xmlns="http://www.w3.org/1999/xhtml">Passport Photo</a></p>
我一直在尝试找出添加 xmlns anchor 的位置,但无法将其缩小到任何特定的范围。
编辑:我已经尝试在 ajax 调用中强制使用 dataType:"html"...没有变化。
最佳答案
您的选择器代表的是 a
标签中的内容。
你的问题的一个更小的版本是:
html:
<a id="test"></a>
js:
$('#test').html('<p>test</p>');
结果:
<a id="test"><p><a xmlns="http://www.w3.org/1999/xhtml">test</a></p></a>
改变周围的东西,这样你就不会将 p
标签放在 a
标签中,或者执行以下操作:
$('#test').empty().append('<p>test</p>');
关于javascript - Firefox 添加 <a xmlns ="http://www.w3.org/1999/xhtml">,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3736474/