我想确保 after(( 仅在 focusout(( 被处理后执行,而不是在 jquery 中之前执行。以下是代码:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<form action="index.php" method="post">
<label for="lblIosDownload">Todays iOS Downloads</label>
<input name="txtIosDownloads" type="number" > <br>
<label for="lblAndroidDownload">Todays Android Downloads</label>
<input name="txtAndroidDownloads" type="number" ><br>
<label for="iosSignUps">Today's Ios Sign ups</label>
<input name="txtIosSignUps" type="number" ><br>
<label for="lblAndroidSignUps">Todays Android SignUps</label>
<input name="txtAndroidDownloads" type="number" ><br>
</form>
<script>
$(document).ready(function(){
$("input[name='txtIosSignUps']").focusout(function(e){
e.preventDefault();
var numberOfSignups = $(this).val();
alert(numberOfSignups);
}).after("<div style='color:red'>Hi<div>");
});
</script>
</body>
将after()
调用移动到事件处理程序内,使其不会在页面加载时发生,而是在事件发生时发生
$(document).ready(function(){
$("input[name='txtIosSignUps']").focusout(function(e){
e.preventDefault();
var numberOfSignups = $(this).val();
alert(numberOfSignups);
$(this).after("<div style='color:red'>Hi<div>");
});
});