从输入 jquery 获取值
Getting value from input jquery
我正在尝试从输入中获取值并通过脚本传递它以注册用户,但存储它没有任何运气。我设置的用于测试的警报不显示任何值。以下是我必须获取用户名的值并将其传递到脚本中的内容:
<form id ="form-signin" class="form-signin" action="" method="">
<input type="text" id="username" class="form-control" placeholder="Username" required autofocus>
<input type="email" class="form-control" placeholder="Email" required autofocus>
<input type="password" class="form-control" placeholder="Password" required>
<input type="submit" id="createUser" class="btn btn-lg btn-default btn-block" value="Sign Up" />
</form>
<script type="text/javascript">
Parse.initialize("u3BTp3Efoko8hbNhl5MCeli8Kd2iiEk8mE4vYgn4", "tQEGymAWeB8Tr2LA3YDGoq2Lt2xpGMW9ikeFSTtD");
//get the input data
var username = $('#username').val();
//set the user
var user = new Parse.User();
$( "form" ).submit(function( event ) {
alert( "Error: " + username + " " );
user.set("username", " " + username + " ");
user.set("password", "my pass");
user.set("email", "email@example.com");
// other fields can be set just like with Parse.Object
user.set("phone", "415-392-0202");
user.signUp(null, {
success: function(user) {
// Hooray! Let them use the app now.
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
alert("Error: " + error.code + " " + error.message);
}
});
});
</script>
您需要在提交处理程序中读取用户名的值。
您正在读取字段的值,#username
加载页面时为空白,一旦读取该值并将其分配给变量,则当您更新输入值时,变量值将不会更新。
//dom ready handler
jQuery(function ($) {
Parse.initialize("u3BTp3Efoko8hbNhl5MCeli8Kd2iiEk8mE4vYgn4", "tQEGymAWeB8Tr2LA3YDGoq2Lt2xpGMW9ikeFSTtD");
//set the user
var user = new Parse.User();
$("form").submit(function (event) {
//get the input data
var username = $('#username').val();//read the user value in s
alert("Error: " + username + " ");
user.set("username", " " + username + " ");
user.set("password", "my pass");
user.set("email", "email@example.com");
// other fields can be set just like with Parse.Object
user.set("phone", "415-392-0202");
user.signUp(null, {
success: function (user) {
// Hooray! Let them use the app now.
},
error: function (user, error) {
// Show the error message somewhere and let the user try again.
alert("Error: " + error.code + " " + error.message);
}
});
});
})
相关文章:
- 在for循环中未获取JQuery/JavaScript对象值
- 点击获取jQuery上的href属性
- 如何获取jQuery Confirm(jConfirm)值并使用该值检查条件
- 通过传递的参数位置获取jQuery中图像的宽度
- MVC Syncfusion Grid-HTML EJ Grid-获取Jquery中所选行的主键
- 如何获取 jQuery 以触发本机自定义事件处理程序
- 如何获取 jQuery 回调触发返回值
- 如何在wordpress插件中获取jquery中的img url和文件url
- 我想知道如何只激活表单提交,而不获取jquery中ajax url的值
- 如何获取jQuery集合中的第k个元素..作为JQUERY元素
- 从aspx.cs页面获取jquery post中的Null响应而不是json
- 如何获取 jquery 变量 childeren
- 如何从每个对象获取jQuery的“title”和“url”值
- 如何动态获取jquery noConflict()的引用
- 用于获取jQuery元素或值的方法
- 获取jquery数组对象的第n项
- 获取jquery确认在函数中返回的结果
- 获取JQuery UI自动完成元素的索引
- 获取jQuery UI排序后的ID数组
- 获取 jQuery DataTable 中的元素