【发布时间】:2012-11-24 08:45:00
【问题描述】:
我想在用户点击链接时设置一个 cookie 值。 我正在使用以下代码:
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="../../Scripts/jquery.cookie.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
function changeLang(lang) {
$.cookie('myCulture', lang);
window.location.reload();
return false;
}
});
</script>
HTML
<a href="#" onclick="changeLang('da-DK')"><img src="../../Content/images/danishFlag.png" height="35px" width="35px"/></a>
<a href="#" onclick="changeLang('sv-SE')"><img src="../../Content/images/swedishFlag.png" height="35px" width="35px"/></a>
看起来很简单的代码,但是当我点击链接时,浏览器出现错误。 它说。
ReferenceError: changeLang is not defined
changeLang("da-DK");
我哪里做错了??
【问题讨论】:
-
将您的函数重新定位到文档外
标签: javascript jquery html asp.net-mvc cookies