2013-05-18 26 views

回答

1

你的HTML改成这样:

<input type="text" name="name" maxlength="15" id="name" onkeyup="check_length(this)" /> 

并添加此功能到您的javascript:

function check_length(thisObject){ 
    if(thisObject.value.length>14){ajaxFunction(thisObject.value)} 
} 

编辑:

This happens when you define the functions in the head part and call them, when the document is not yet initialized. Move the script part, where the initialization happens and try it out.

我把你的示例代码(保存在一个空白的html文件中,并测试它):

<input type="text" name="name" maxlength="15" id="name" onkeyup="check_length(this)" /> 
<script> 
function check_length(thisObject){ 
    if(thisObject.value.length>14){ajaxFunction(thisObject.value)} 
} 
function ajaxFunction(thisObjectValue) 
{ 
    console.log(thisObjectValue); 
    /// Do things .... 
} 
</script> 
+0

@siamek没有工作兄弟:(它宠坏了我的脚本功能。 – user2373405

+0

@ user2373405它为我工作。 **再次复制代码**,如果它仍然不起作用,请检查您的控制台以查看出现了什么错误。 –

+0

错误:'[19:31:48.804] ReferenceError:ajaxFunction未定义@ ..........:12'(第12行是'if(thisObject.value.length> 14){ajaxFunction(thisObject .value)}' – user2373405

相关问题