jfr*_*how 6 javascript jquery xml-namespaces
编辑:由于ajax调用,这不会发生.我改变它以使用来自TinyMCE组件的值来获得乐趣,我得到同样的东西.
content = tinyMCE.get('cComponent').getContent(); //content at this point is <p>test</p>
valueToDisplay = content;
Run Code Online (Sandbox Code Playgroud)
如果我做:
jQuery(selector).html(valueToDisplay);
Run Code Online (Sandbox Code Playgroud)
我明白了:
<p><a xmlns="http://www.w3.org/1999/xhtml">test</a></p>
Run Code Online (Sandbox Code Playgroud)
有没有人在使用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;
}
Run Code Online (Sandbox Code Playgroud)
如果我在此时检查值,我会得到预期值
console.log(returnValue) //output this --> <p>Passport Photo</p>
Run Code Online (Sandbox Code Playgroud)
但是,当我使用jQuery(选择器).html将其插入现有锚点时
我明白了:
<p><a xmlns="http://www.w3.org/1999/xhtml">Passport Photo</a></p>
Run Code Online (Sandbox Code Playgroud)
我一直在试图找出添加xmlns锚的位置,但不能将其缩小到任何特定的范围.
编辑:我已经尝试在ajax调用中强制dataType:"html"...没有变化.
您的选择器表示某个a标签中的内容.
您问题的最小版本将是:
HTML:
<a id="test"></a>
Run Code Online (Sandbox Code Playgroud)
JS:
$('#test').html('<p>test</p>');
Run Code Online (Sandbox Code Playgroud)
结果:
<a id="test"><p><a xmlns="http://www.w3.org/1999/xhtml">test</a></p></a>
Run Code Online (Sandbox Code Playgroud)
改变一切,这样你就不会在p标签中a添加标签,或者执行以下操作:
$('#test').empty().append('<p>test</p>');
Run Code Online (Sandbox Code Playgroud)