2013-05-18 27 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

相關問題