JavaScript运行时错误:对象不存在';t支持属性或方法';包含';

JavaScript运行时错误:对象不存在';t支持属性或方法';包含';,javascript,Javascript,我已经在母版页中编写了以下代码 <script type="text/javascript"> if (window.location.pathname.contains('Page1.aspx')) { var js = document.createElement("script"); js.type = "text/javascript"; js.src

我已经在母版页中编写了以下代码

 <script type="text/javascript">
            if (window.location.pathname.contains('Page1.aspx')) {
                var js = document.createElement("script");

                js.type = "text/javascript";
                js.src = 'http://code.jquery.com/jquery-1.8.3.js';


            }
            if (window.location.pathname.contains('Page2.aspx')) {
                var js = document.createElement("script");

                js.type = "text/javascript";
                js.src = 'http://code.jquery.com/jquery-1.9.1.js';


            }    

        </script>

if(window.location.pathname.contains('Page1.aspx')){
var js=document.createElement(“脚本”);
js.type=“text/javascript”;
js.src=http://code.jquery.com/jquery-1.8.3.js';
}
if(window.location.pathname.contains('Page2.aspx')){
var js=document.createElement(“脚本”);
js.type=“text/javascript”;
js.src=http://code.jquery.com/jquery-1.9.1.js';
}    
在asp.net应用程序中,我有三个页面page1、page2、page3,它们由同一母版页继承。当我尝试访问页面3时,它显示错误:
“JavaScript运行时错误:对象不支持属性或方法‘contains’”

,除非您自己定义了它(您还没有定义),否则strings1中不存在
contains()
。使用,这实际上是相同的事情

例如:

console.log('abcdefg'.includes('def')); // true
console.log('abcdefg'.includes('ghi')); // false
如果必须支持较旧的浏览器(如Internet Explorer),请使用
indexOf()

无论如何,在两个页面上使用两个不同版本的jQuery是一个可怕的想法——尽可能避免使用它



1:从技术上讲,这不是100%正确的:有一个内置的
contains()
函数,但它被重命名为
includes()

为什么在两个页面上使用不同版本的jQuery?因为母版页中存在jQuery冲突。
console.log('abcdefg'.indexOf('def') !== -1); // true
console.log('abcdefg'.indexOf('ghi') !== -1); // false