当我写这段代码时:
<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>并引用ScriptManager中的jQuery库:
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/scripts/jquery-1.4.1.min.js" ScriptMode="Release" />
</Scripts>
</asp:ScriptManager>当我在上面的代码中commnet并在head部分引用jQuery时,所有的东西都是ok.but:
<script src="scripts/jquery-1.4.1.min.js" type="text/javascript"></script>调试器警告我endsWith:Object doesn't support this property or method
为什么asp.net会有这样的行为?
谢谢
发布于 2011-08-27 16:32:14
在您的代码行中:
if (src.endsWith("plus.png"))假设string对象有一个名为endsWith()的方法,但标准javascript没有这样的方法。有各种扩展可以将该方法添加到string对象中(这是一个易于编写的扩展),但除非专门将其添加到String对象原型中,否则不能假定它就在那里。
我不能解释为什么它会工作,除非两个配置中的一个有一个安装了这个扩展的库。它不是jQuery的一部分。
这里有一个关于添加endsWith()方法的问题:endsWith in JavaScript和我碰巧喜欢这个讨论中的帖子:endsWith in JavaScript。
https://stackoverflow.com/questions/7213276
复制相似问题