Moz say's everything is ok! IE say's object expected everywhere..
for example this my make a box function (in all.js file);
function kutuyap(Eid,iduzan,开发者_JAVA百科text,yer,ekle){
var div;
if (document.createElement && (div = document.createElement('div'))) {
div.name = div.id = Eid+iduzan;
document.getElementById(yer).appendChild(div);
}
//$('#'+yer).append("<div id="+Eid+iduzan+"></div>")
$('#'+Eid+iduzan).addClass("minikutu");
$('#'+Eid+iduzan).html(" "+text+'<span id='+Eid+'y'+iduzan+' class="yokedici">X</span>');
$("#"+Eid+'y'+iduzan).attr("onclick","kutusil('"+Eid+"y"+iduzan+"','"+iduzan+"','"+ekle+"');");
$('#'+ekle).val($('#'+ekle).val()+Eid+'-');
}
and after that i call function like this;
HTML;
<select name="Mturs" class="inputs" id="Mturs">
<option value="0" selected="selected">Choise One</option>
<option value="4">Pop</option>
<option value="3">Pop-Rock </option>
<option value="5">Rock (Yabancı)</option>
</select>
<input name="secMtur" id="secMtur" value="" type="hidden">
<script>
$('#Mturs').live('change', function() {
$('#Mturs :selected').each(function (i) {
if ( $('#Mturs :selected').val() != 0 ) {
secMturde=$('#secMtur').val().indexOf($('#Mturs :selected').val()+'-');
splitter=$('#secMtur').val().split("-")
if(splitter.length<=12){
if (secMturde<0) {
kutuyap($('#Mturs :selected').val(),'mtur',$(this).html(),'divmtur','secMtur');
}else{
alert("Choisen before")
}
}else{
alert("Max limit is 12 !")
}
}
});
});
</script>
sory for my realy bad english..
edit: and i have this tags;
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js">
</script>
<script type="text/javascript" src="alljs.js"></script>
$("#"+Eid+'y'+iduzan).attr("onclick","kutusil('"+Eid+"y"+iduzan+"','"+iduzan+"','"+ekle+"');");
Don't use attr
to set event handlers like onclick
, it won't generally work in IE.
It's also a really bad idea to be creating JavaScript code from strings in that way, too. Especially as if any of those variables can include a '
, "
, \
, &
, <
or U+2018/2019 character you've got trouble.
Instead use inline function expressions, picking up the variables you already have from the outer function using a closure:
$("#"+Eid+'y'+iduzan).click(function() {
kutusil(Eid+'y'+iduzan, iduzan, ekle);
});
Again:
$('#'+Eid+iduzan).html(" "+text+...
If text
can contain <
/&
you've potentially got cross-site-scripting problems there. Don't stick HTML strings together from text content. Use .text(text)
to write plain text to an element.
if (document.createElement && (div = document.createElement('div'))) {
There is no need for this checking. document.createElement
exists in every browser (it is DOM Level 1 Core) and can never return null
.
div.name
There's no such property on divs.
bobince's answer is excellent; do pay very careful attention to XSS vulnerabilities.
I would add only one other tidbit that caused me some consternation early on, and is a best practice that you should consider adopting:
Do not use primitives or core attribute/function names in your script unless you are purposefully doing so (e.g in the case of overriding).
Take this example:
01: $.getJSON('/doSomething.php?r=' + new Date().getTime(),function(json){
02: var someinfo = "";
03: $.each(json.somearray, function(i,data){
04: someinfo = someinfo + data.class + " ";
05: });
...
Mozilla is perfectly fine with the above code; Internet Explorer, however, chokes on the ".class" reference (line 04).
This issue can be difficult to identify since the error prevents IE from parsing other javascript on the page; the result is that IE throws an error on all (custom) function calls, rather than just the function where the actual problem is.
The solution, as previously mentioned, is to replace ".class" with some other string
04: someinfo = someinfo + data.classification + " ";
Happy coding!
Try changing this:
src="ajax.goog...
to this:
src="http://ajax.goog...
Usually the http:// is necessary, this might be why your scripts were not loaded.
精彩评论