.bind()无法设置cookie

I have a function to set cookies, and i have .bind() set on some of my links so that they trigger the cookie function when clicked. Right now, when they are clicked no cookie is set. I've spent hours on this and cant figure it out.

<script type="text/javascript"> function createCookie(name,value,days) { 
if (days) {
    var date = new Date();
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    var expires = ";
 expires=" + date.toGMTString();
}
else {
    var expires = "";
}
document.cookie = name + "=" + value + expires + "; path=/";
}
$("a#en").bind("click", function () {
    createCookie('TR_LNG', 'en', 90);
});
$("a#fr").bind("click", function () {
    createCookie('TR_LNG', 'fr', 90);
});
$("a#de").bind("click", function () {
    createCookie('TR_LNG', 'de', 90);
});
$("a#ja").bind("click", function () {
    createCookie('TR_LNG', 'ja', 90);
});
$("a#pl").bind("click", function () {
    createCookie('TR_LNG', 'pl', 90);
});
$("a#es").bind("click", function () {
    createCookie('TR_LNG', 'es', 90);
});
</script> 

HTML

<div id="langselectsplash" class="langselectsplash">
    <div id="select">
        <img src="http://mysite.org/wp-content/uploads/2012/08/sarvalogo2.png"
        />
        <p>
            <style>
            #tr_setdeflang {
                display:none;
            }

            </style>
            <div class="no_translate transposh_flags">
                <a id="en" href="/about/" class="tr_active">English</a>
                <a id="fr" href="/fr/about/">Français</a>
                <a id="de" href="/de/about/">Deutsch</a>
                <a id="ja" href="/ja/about/">日本語</a>
                <a id="pl" href="/pl/about/">Polski</a>
                <a id="es" href="/es/about/">Español</a>
            </div>
        </p>
    </div>
</div>
<div id="langsplashfade"></div>

The PHP code that outputs the above:

<?php
echo "<script type=\"text/javascript\"> function createCookie(name,value,days) { 
if (days) { 
var date = new Date();
 date.setTime(date.getTime()+(days*24*60*60*1000));
 var expires = \";
 expires=\"+date.toGMTString();
} else { 
var expires = \"\";}document.cookie = name+\"=\"+value+expires+\"; path=/\";}
";
foreach ($args as $langrecord) {
    echo "$(\"a#{$langrecord['isocode']}\").bind(\"click\", function() {createCookie('TR_LNG','{$langrecord['isocode']}',90);});
";
}
echo "</script>";
?>
   <?php
echo " <div id=\"langselectsplash\" class=\"langselectsplash\"><div id=\"select\"><img src=\"http://mysite.org/wp-content/uploads/2012/08/sarvalogo2.png\" /><p>";
?>
           <?php
echo "<style>#tr_setdeflang{display:none;}</style><div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
foreach ($args as $langrecord) {
    echo "<a id=\"{$langrecord['isocode']}\" href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '') . '>' . "{$langrecord['langorig']}</a>";
}
echo "</div>";
?>

You need to put the code where you are binding events on the DOM ready event:

$(document).ready(function(){
//Your code
});

or

$(function(){
//Your code
});

look at your log:

SyntaxError: unterminated string literal
var expires = ";

You have an error I think you want:

function createCookie(name,value,days) { 
    var expires = "";
    if (days) { 
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        expires = ";expires=" +date.toGMTString();
    }
    document.cookie = name + "=" + value + expires + ";path=/";
}

because you are opening a string on one line and never closes it at the moment. And the code could be rewritten to:

$("#en, #fr, #de, #ja, #pl, #es").bind("click", function() {
    createCookie('TR_LNG', this.id, 90);
});

or even better add a css Class on those anchor links and target that instead (for example with your current site: $(".transposh_flags a") would do the same as the code above.