when I write this code:
<script type="text/javascript">
function showhide(master, detail) {
var src = $(master).children()[0].src;
if (src.endsWith("plus.png"))
src = src.replace('plus.png', 'minus.png');
else
src = src.replace('minus.png', 'plus.png');
$(master).children()[0].src = src;
$(detail).slideToggle("normal");
}
</script>
and reference jQuery library in ScriptManager:
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/scripts/jquery-1.4.1.min.js" ScriptMode="Release" />
</Scripts>
</asp:ScriptManager>
every thing is ok.but when I commnet above code and reference jQuery In head part:
<script src="scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
debugger alert me that for endsWith : Object doesn't support this property or method
why asp.net has this behaivior?
thanks
In this line of your code:
You are assuming that the string object has a method called
endsWith(), but standard javascript does not have such a method. There are various extensions that add that method to the string object (it’s a simple one to write), but you cannot assume it is there unless you’ve specifically added it to the String object prototype.I can’t explain why it ever works unless one of the two configurations has a library that installs this extension. It is not part of jQuery.
Here’s an earlier SO question about adding an endsWith() method: endsWith in JavaScript and I happen to like this particular post in that discussion: endsWith in JavaScript.