前置/后置不起作用(Opera,Safari,Chrome)

Comarades,

我尝试使用append和prepend(),但没有一个控件工作。 谁能帮助我? 在Internet Explorer和Firefox中工作。

代码:

  Untitled Document    selEstrutura = function(strComponent, strDestino) { var objDest = $('#' + strDestino); var objComp = $('#' + strComponent); if ((objComp != null) && (objDest != null)) { $('#' + strDestino + ' img').remove(); objDest.append('<img id="' + strDestino + '" src="' + objComp.val() + '"'); if ((strDestino.trim() == 'eixoTracionado1') || (strDestino.trim() == 'eixoTracionado2')) { $('#eixoEstruturaPt1 img').remove(); $('#eixoEstruturaPt1').append('<img id="eixoEstruturaPt1" src="estrutura_semrodas.gif"'); $('#eixoEstruturaPt2 img').remove(); $('#eixoEstruturaPt2').append('<img id="eixoEstruturaPt2" src="estrutura_semrodas.gif"'); } } }   
Tração: 
  Única Simples Dupla
Tracionado(1): 
  Simples Duplo
Tracionado(2): 
  Simples Duplo
Qtd Estepes: 
  01 02 03

Sugestions(修改)

执行一些建议的更改,仍然无法正常工作。

  selEstrutura = function(strComponent, strDestino) { var objDest = $('#' + strDestino); var objComp = $('#' + strComponent); if ((objComp != null) && (objDest != null)) { $('#' + strDestino + ' img').remove(); objDest.append('<img id="' + strDestino + '_img" src="' + objComp.val() + '"'); if ((strDestino.trim() == 'eixoTracionado1') || (strDestino.trim() == 'eixoTracionado2')) { $('#eixoEstruturaPt1 img').remove(); $('#eixoEstruturaPt1').append('<img id="eixoImgEstruturaPt1" src="estrutura_semrodas.gif"'); $('#eixoEstruturaPt2 img').remove(); $('#eixoEstruturaPt2').append('<img id="eixoImgEstruturaPt2" src="estrutura_semrodas.gif"'); } } }  

好吧,有一件事对我来说很奇怪,就是你要添加标签,其中“id”值与其他标签中的其他“id”值完全重复。 也许WebKit不喜欢这样; 这绝对是件坏事。

尝试这样的更改:

 objDest.append(' 

它也让我觉得你好像忘记了元素末尾的“>”! 应该是这样的:

 objDest.append(''); 

(如果你的DOCTYPE是XHTML,你当然应该使用“/>”,但你的是“html”。)

这些永远不会为空。 它们将始终包含一个jQuery对象(即使它没有元素)。

 if ((objComp != null) && (objDest != null)) 

您应该使用length属性进行测试。

 if ((!objComp.length) && (!objDest.length)) 

另外,据我所知,您正在创建一个与现有strDestino元素具有相同ID的新元素。

 objDest.append(' 

您不能拥有2个具有相同ID的元素。

来源工作:Opera,Safari,Chrome,IE,Mozilla。

 selEstrutura = function(strComponent, strDestino) { $('#' + strDestino + ' img').remove(); $('#' + strDestino).append(''); if ((strDestino == 'eixoTracionado1') || (strDestino == 'eixoTracionado2')) { $('#eixoEstruturaPt1 img').remove(); $('#eixoEstruturaPt1').append(''); $('#eixoEstruturaPt2 img').remove(); $('#eixoEstruturaPt2').append(''); } } 

我做了朋友建议的更改,但在某些浏览器中没有工作。 经过一些测试,我发现方法“.Trim()”无法正常工作。

感谢大家的帮助

有同样的问题。 php脚本生成了一个传递给jquery.each()的json。 Firefox以正确的顺序显示行,而chrome以相反的方式显示行。

问题是由对象键引起的。 Chrome在foreach之前使用键对数组进行了排序。 在我的情况下,解决方案是使用自动递增的值作为键而不是我的旧版本号键,这是相反的。