js 函数在我的站点中不起作用,但是当我在JSFIDDLE中尝试它时,它显示工作正常。我已经DOM
准备好了,但它不会触发任何东西。我用firefox检查过,输入值根本没有发布。用户停止输入后,如何让 JS 功能正常启动?
JS
<script>
$(document).ready(function() {
var timer = null;
var dataString;
function submitForm(){
alert("success");
$.ajax({ type: "POST",
url: "index.php",
data: dataString,
success: function(result){
alert("success");
/*$('#special').append('<p>' + $('#resultval', result).html() + '</p>');*/
}
});
return false;
}
$('#submit').on('keyup', function() {
clearTimeout(timer);
timer = setTimeout(submitForm, 2000);
var name = $("#name").val();
dataString = 'name='+ name;
});
});
</script>
HTML
<input id="name" name="name" type="text" class="field text medium" value="<? $url ?>" maxlength="255" tabindex="1" />