jQuery 类型错误:$.browser 未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14798403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeError: $.browser is undefined
提问by user1972934
I am using msdropdown image combo box to create dropdown select options. when i run this code locally on my PC, everything works great. But when i run it on go daddy servers, the msdropdown becomes disabled.
我正在使用 msdropdown 图像组合框来创建下拉选择选项。当我在我的 PC 上本地运行此代码时,一切正常。但是当我在 go daddy 服务器上运行它时,msdropdown 被禁用。
It doesn't work on any browsers. Firebug displays the error as:
它不适用于任何浏览器。Firebug 将错误显示为:
TypeError: $.browser is undefined
Please help me with this.
请帮我解决一下这个。
echo <<<_START
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>profile</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="generator" content="HAPedit 3.1">
<link rel="stylesheet" href="profile.css" type="text/css">
<link rel="stylesheet" type="text/css" href="dd.css" />
<link rel="stylesheet" href="javascript/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.0.js"></script>
<script type="text/javascript" src="jQuery.js"></script>
<script src="javascript/jquery-ui.js"></script>
<script type="text/javascript" src="javascript/drop.js"></script>
<script src="jquery.dd.min.js"></script>
<script type="text/javascript" src="jquery.blockUI3.js"></script>
<script type="text/javascript" src="javascript/req.js"></script>
<link rel="stylesheet" href="css/body.css" />
<script>
$(function() {
$( "#datepicker" ).datepicker({dateFormat: 'dd-mm-yy', minDate: 0, maxDate: "+0M +5D"
});
});
</script>
<script type="text/javascript">
<!--
function otherSelect() {
var other = document.getElementById("otherBox");
if (document.getElementById("form3").place.options[document.getElementById("form3").place.selectedIndex].value == "other") {
other.style.visibility = "visible";
}
else {
other.style.visibility = "hidden";
}
}
//-->
</script>
</head>
<body id="body">
<div id="container">
<div class="header">
<a href="profile.php" class="logo">
<img title="Title" alt="Alter" src="images/logo.png" border="0" height="60px" width="200px">
</a>
<a style="text-decoration:none; margin-top:15px; font-family:Bookman Old Style; font-size:12px; color:#FFFFFF; font-weight:bold;" href="logout.php?id='$session_id'" class="req">
Logout
</a>
<a href="notification.php?email='$encrypted_string'" class="req1">
<img border="0" title="Notifications" alt="Notifications" src="images/notification.png" height="60px" width="60px"><div class="text1">$numbr</div>
</a>
<a href="request.php?email='$encrypted_string'" class="req2">
<img border="0" title="requests" alt="Requests" src="images/request.png" height="60px" width="60px"><div class="text">$req</div>
</a>
</div>
<div id="navigation">
<div id="picture"><img src="$img">
<h1 id="display" style="margin-left:30px;">$name</h1><hr>
<table style="background-color:#81F781;font-family:Chaparral Pro,corbel; font- size:17px; color:#1C1C1C; width:100%;" border="1" cellpadding="25">
<tr><th>Requests($n)</th></tr></table>
</div>
</div></div>
<div style="margin-top: 90px;" id="conte">
_START;
echo <<<_START
</div>
<div id="accept" style="display:none">
<form method="post" id="form3" action="cnfrm.php">
<br><table border="0" style="width:100%;" cellspacing="4" cellpadding="4"><tr> <td style="font-family:Chaparral Pro,corbel; font-size:17px; color:#1C1C1C;">Meeting Date: <input type="text" id="datepicker" name="date"/></td>
<td style="font-family:Chaparral Pro,corbel; font-size:17px; color:#1C1C1C;">@ about<input type="text" id="time" size="3">AM<input type="radio" name="time2" id="time2" value="am"> | PM<input type="radio" name="time2" id="time2" value="pm"></td></tr>
_START;
echo <<<H
<tr><td valign="top" rowspan="2">
<select id="place" name="place" style="width:300px;" onchange="otherSelect()">
<option value="" data-description="Choose your meeting place" selected="selected">Meet me @</option>
<option value="LC" data-image="image/msdropdown/icons/meet.png" data-description="Limbdi Corner">L.C</option>
<option value="VT" data-image="image/msdropdown/icons/meet.png" data-description="Vishwanath temple">V.T</option>
<option value="H.G" data-image="image/msdropdown/icons/meet.png" data-description="Hyderabaad Gate">H.G</option>
<option value="D.G Corner" data-image="image/msdropdown/icons/meet.png" data-description="Dhanrajgiri Corner">D.G corner</option>
<option value="Library" data-image="image/msdropdown/icons/meet.png" data-description="IIT Library">Library</option>
<option value="other" data-image="image/msdropdown/icons/meet.png" data-description="Add your own...">Other place</option>
</select> </td></tr>
H;
This problem has been solved:msdropdown updateand download the latest files.
此问题已解决:msdropdown 更新并下载最新文件。
Thanks everyone
谢谢大家
回答by daniel.moura
just put the $.browser code in your js
只需将 $.browser 代码放在您的 js 中
var matched, browser;
jQuery.uaMatch = function( ua ) {
ua = ua.toLowerCase();
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
[];
return {
browser: match[ 1 ] || "",
version: match[ 2 ] || "0"
};
};
matched = jQuery.uaMatch( navigator.userAgent );
browser = {};
if ( matched.browser ) {
browser[ matched.browser ] = true;
browser.version = matched.version;
}
// Chrome is Webkit, but Webkit is also Safari.
if ( browser.chrome ) {
browser.webkit = true;
} else if ( browser.webkit ) {
browser.safari = true;
}
jQuery.browser = browser;
回答by sdespont
$.browser
has been removed from JQuery 1.9. You can to use Modernizrproject instead
$.browser
已从 JQuery 1.9 中删除。您可以改用Modernizr项目
http://jquery.com/upgrade-guide/1.9/#jquery-browser-removed
http://jquery.com/upgrade-guide/1.9/#jquery-browser-removed
UPDATE TO SUPPORT IE 10 AND IE 11 (TRIDENT version)
更新以支持 IE 10 和 IE 11(TRIDENT 版本)
To complete the @daniel.moura answer, here is a version which support IE 11 and +
要完成@daniel.moura 的回答,这里有一个支持 IE 11 和 +的版本
var matched, browser;
jQuery.uaMatch = function( ua ) {
ua = ua.toLowerCase();
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie)[\s?]([\w.]+)/.exec( ua ) ||
/(trident)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
[];
return {
browser: match[ 1 ] || "",
version: match[ 2 ] || "0"
};
};
matched = jQuery.uaMatch( navigator.userAgent );
//IE 11+ fix (Trident)
matched.browser = matched.browser == 'trident' ? 'msie' : matched.browser;
browser = {};
if ( matched.browser ) {
browser[ matched.browser ] = true;
browser.version = matched.version;
}
// Chrome is Webkit, but Webkit is also Safari.
if ( browser.chrome ) {
browser.webkit = true;
} else if ( browser.webkit ) {
browser.safari = true;
}
jQuery.browser = browser;
// log removed - adds an extra dependency
//log(jQuery.browser)
回答by ritesh
Just include this script
只需包含此脚本
http://code.jquery.com/jquery-migrate-1.0.0.js
http://code.jquery.com/jquery-migrate-1.0.0.js
after you include your jquery javascript file.
在你包含你的 jquery javascript 文件之后。
回答by Paul Preibisch
I placed the following html in my code and this cleared up the $.browser error
我将以下 html 放在我的代码中,这清除了 $.browser 错误
<script src="http://code.jquery.com/jquery-migrate-1.0.0.js"></script>
Hope this helps u
希望这对你有帮助
回答by IanO.S.
$().live(function(){}); and jQuery.browser is undefined in jquery 1.9.0- $.browser was deprecated in jquery update
$().live(function(){}); 和 jQuery.browser 在 jquery 1.9.0 中未定义- $.browser 在 jquery 更新中被弃用
sounds like you are using a different version of jquery 1.9 in godaddy so either change your code or include the migrate plugin http://code.jquery.com/jquery-migrate-1.0.0.js
听起来您在 godaddy 中使用的是不同版本的 jquery 1.9,因此请更改您的代码或包含迁移插件http://code.jquery.com/jquery-migrate-1.0.0.js
回答by ikuchris
Replace your jquery files with followings :
用以下内容替换您的 jquery 文件:
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
回答by Brian Morearty
Somewhere the code--either your code or a jQuery plugin--is calling $.browser
to get the current browser type.
某处代码(您的代码或 jQuery 插件)正在调用$.browser
以获取当前浏览器类型。
However, early has year the $.browser
function was deprecated. Since then some bugs have been filed against it but because it is deprecated, the jQuery team has decided not to fix them. I've decided not to rely on the function at all.
然而,早有一年该$.browser
功能被弃用。从那时起,一些错误已经被提交,但因为它已被弃用,jQuery 团队决定不修复它们。我决定完全不依赖该功能。
I don't see any references to $.browser
in your code, so the problem probably lies in one of your plugins. To find it, look at the source code for each plugin that you've referenced with a <script>
tag.
我$.browser
在你的代码中没有看到任何引用,所以问题可能出在你的插件之一。要找到它,请查看您使用<script>
标记引用的每个插件的源代码。
As for how to fix it: well, it depends on the context. E.g., maybe there's an updated version of the problematic plugin. Or perhaps you can use another plugin that does something similar but doesn't depend on $.browser
.
至于如何修复它:嗯,这取决于上下文。例如,可能有问题插件的更新版本。或者,也许您可以使用另一个插件来做类似的事情但不依赖于$.browser
.
回答by Raja Ram T
i did solved it using jQuery migrate link specified below:
我确实使用下面指定的 jQuery 迁移链接解决了它:
<script src="http://code.jquery.com/jquery-migrate-1.0.0.js"></script>
回答by Ankur Modi
I did solved using this jquery for Github
我确实使用这个 jquery for Github 解决了
<script src="http://code.jquery.com/jquery-migrate-1.0.0.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.0.0.js"></script>
Please Refer this link for more info. https://github.com/Studio-42/elFinder/issues/469
请参阅此链接以获取更多信息。 https://github.com/Studio-42/elFinder/issues/469