火狐浏览器 和 ie浏览器的event获得 和 阻止 方式不同

This commit is contained in:
lizanle 2015-09-25 15:55:29 +08:00
parent 926bdd81e8
commit c8cbab2d50
3 changed files with 48 additions and 25 deletions

View File

@ -1,23 +1,7 @@
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' ,'new_user' %>
<script>
$(function(){
document.getElementById('forum_name').onkeydown = function()
{
var n = 0;
var str = this.value;
for (i = 0; i < str.length; i++) {
var leg = str.charCodeAt(i);//ASCII码
if (leg > 255) {
n += 2;
} else {
n += 1;
}
}
if(n >= 160 && event.keyCode != 8)
event.returnValue = false;
}
})
function check_and_submit(doc){
$("#error").html('').hide();
@ -66,4 +50,29 @@
autoTextarea(textarea);
var textarea1 = document.getElementById('forum_desc');
autoTextarea(textarea1);
$(function(){
$('#forum_name').keypress(function(e)
{
var n = 0;
var str = this.value;
for (i = 0; i < str.length; i++) {
var leg = str.charCodeAt(i);//ASCII码
if (leg > 255) {
n += 2;
} else {
n += 1;
}
}
if(n >= 160 && e.keyCode != 8)
if(document.all)
{
e.returnValue = false;
}
else
{
e.preventDefault();
}
})
})
</script>

View File

@ -49,7 +49,7 @@
$("#reorder_popu").removeClass("sortArrowActiveD");
add_class("reorder_time");
});
document.getElementById('forum_name').onkeydown = function()
$('#forum_name').keypress( function(e)
{
var n = 0;
var str = this.value;
@ -61,9 +61,16 @@
n += 1;//英文,不多说了
}
}
if(n >= 160 && event.keyCode != 8)
event.returnValue = false;
}
if(n >= 160 && e.keyCode != 8)
if(document.all)
{
e.returnValue = false;
}
else
{
e.preventDefault();
}
})
});
function check_and_submit(doc){
$("#error").html('').hide();

View File

@ -337,7 +337,7 @@ var autoTextarea = function (elem, extra, maxHeight) {
};
function limitStrsize(id,length){
document.getElementById(id).onkeydown = function()
$('#'+id).keypress(function(e)
{
var n = 0;
var str = this.value;
@ -350,9 +350,16 @@ function limitStrsize(id,length){
}
}
if(n >= length && event.keyCode !== 8)
event.returnValue = false;
}
if(n >= length && e.keyCode !== 8)
if(document.all)
{
e.returnValue = false;
}
else
{
e.preventDefault();
}
})
}
/////////////////////////////////////////////////////////////////////////////////////创建项目