0

I have this in jQuery:

$(function(){ 

function updateList(){ 
    //HERE MY FUNCTION
}

});

And :

$(document).ready(function() {
    updateList();
});

they are on the same file. When i load my page, i have ReferenceError: updateList is not defined.

On Firefox and ie9 it's ok....

Do you have any ideas ? Thanks !

Edit : And bonus question, this code doesn't work on IE<9 :

$.ajax({
type: "GET",
url: "rechercheArtisan_ajax.html?action=metier&IDmetier="+secteur_activite, 
dataType: ($.browser.msie) ? "text" : "xml",
success: function( data ) {
var xml;
if (typeof data == "string") {
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.loadXML(data);
} else {
xml = data;
}
// Returned data available in object "xml"
if ( $(xml).is("erreur") )
{
alert( "Erreur : " + $(xml).find("erreur").text() );
}
else
{
$("#id_metier").attr("disabled", "");
updateList( "metier" , $(xml).find("list") );
}
}
});

No error, nothing, just no effect.

4

1 回答 1

3

的范围在updateList里面$(function(){ });。在任何浏览器中都应该没有问题。

为什么需要 2 个不同的就绪处理程序?

或者像下面那样将函数移到文档之外,

<script>
function updateList () { }

$(function () {
   updateList();
});
</script>

或者只使用一个准备好的处理函数。

<script>   
$(function () {
   function updateList () { }

   //some other code

   updateList();
});
</script>
于 2013-03-12T16:51:51.440 回答