我在模板末尾添加了一个基本脚本,用于计算剩余字符并将其显示为实时,如此处所示。 http://jsfiddle.net/r34gM/1/
它似乎不起作用,我没有看到任何更新,我正在
Uncaught SyntaxError: Unexpected token ILLEGAL
这是模板。
<div class="background2div">
<div class="backgroundiv">
<div class="formdiv">
<div class="selltitle">Sell Goodies</div>
<form action="" enctype="multipart/form-data" method="post" data-parsley-validate>
{% csrf_token %}
<div class="forminput">{{ form.body_text }}</div></div>
<div class="suggest2">Describe in detail what makes this product worth buying.</div>
<div class="suggest7">250 character limit</div>
<div class="linecontainer"><div class="forminput"><input type="submit" value="Submit"></div></div>
</form>
</div>
</div>
</div>
<script>
$('#id_body_text').keypress(function(){
if(this.value.length > 160){
return false;
}
$(".suggest7").html("Remaining characters : " +(160 - this.value.length));
});
</script>
答案 0 :(得分:0)
你的源代码中有unicode字符'ZERO WIDTH SPACE'(U + 200B)。
<script>
$('#id_body_text').keypress(function(){
if(this.value.length > 160){
return false;
}
$(".suggest7").html("Remaining characters : " +(160 - this.value.length));
}); // <--- HERE IS THE (U+200B) AFTER THE ';'!
</script>
删除此字符,一切正常。