我开发了一个表单,当用户填写所有输入字段时,将启用提交按钮。我的问题是没有启用提交按钮。我正在使用jQuery。
p <- ggplot(data = dat,aes(x=x,y=y))
p <- p + geom_line(aes(group=z))
p <- p + geom_smooth(data=datMean)
p
请帮我解决这个问题。
答案 0 :(得分:4)
填写所有字段,然后点击“提交”。它正在运作
var UserCampusName = "0";
var EmpID = null;
var FirstName = null;
var LastName = null;
var mobileNo = null;
var EmpEmail = null;
var userRoles = "0";
$('#SubmitUserRole').attr('disabled', 'disabled');
$(function () {
$("#userRoleForm").hover(function(){
UserCampusName = $('#UserCampus').val()
EmpID = $('#UserEmpID').val()
FirstName = $('#UserEmpFirstName').val()
LastName = $('#UserEmpLastName').val()
mobileNo = $('#UserEmpMobileNo').val()
EmpEmail = $('#UserEmpEmail').val()
userRoles = $('#Roles').val()
if ((FirstName.length > 0) && (LastName.length > 0) && (mobileNo.length > 0) && (EmpEmail.length > 0) && (EmpID.length > 0) && (userRoles != 0) && (UserCampusName != 0)) {
$('#SubmitUserRole').removeAttr('disabled');
}
else {
$('#SubmitUserRole').attr('disabled', 'disabled');
}
})
})
&#13;
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<form role="form" class="form-horizontal form-bordered" id="userRoleForm">
<center>
<h2>User Roles & Privileges Set-up</h2></center>
<div class="form-group">
<label class="label1 col-md-4">Select department <span class="required"> * </span> </label>
<div class="col-md-7">
<select class="form-control" id="UserCampus" data-placeholder="Select" tabindex="1">
<option value="Category 0" default disabled selected>--Select--</option>
</select>
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Enter the employee id <span class="required"> * </span> </label>
<div class="col-md-7">
<input id="UserEmpID" type="text" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Enter First Name <span class="required"> * </span> </label>
<div class="col-md-7">
<input id="UserEmpFirstName" type="text" class="form-control"/>
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Enter Middle Name </label>
<div class="col-md-7">
<input id="UserEmpMiddleName" type="text" class="form-control"/>
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Enter Last Name <span class="required"> * </span> </label>
<div class="col-md-7">
<input id="UserEmpLastName" type="text" class="form-control"/>
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Enter Mobile Number <span class="required"> * </span> </label>
<div class="col-md-7">
<input id="UserEmpMobileNo" type="text" class="form-control allownumericwithoutdecimal"/>
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Enter Email Id <span class="required"> * </span> </label>
<div class="col-md-7">
<input id="UserEmpEmail" type="Email" class="form-control"/>
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Select the applicable user role & privileges <span class="required"> * </span> </label>
<div class="col-md-7">
<textarea type="textarea" rowspan="5"> </textarea>
</div>
</div>
<div class="form-group">
<button class="btn btn-primary" id="SubmitUserRole" type="button">submit User</button>
</div>
</form>
&#13;
答案 1 :(得分:0)
尝试以下操作:
<强> HTML 强>
<form role="form" class="form-horizontal form-bordered" id="userRoleForm">
<center>
<h2>User Roles & Privileges Set-up</h2>
</center>
<div class="form-group">
<label class="label1 col-md-4">Select department <span class="required"> * </span> </label>
<div class="col-md-7">
<select class="form-control" id="UserCampus" data-placeholder="Select" tabindex="1">
<option value="0">--Select--</option>
<option value="1">Admin</option>
</select>
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Enter the employee id <span class="required"> * </span> </label>
<div class="col-md-7">
<input id="UserEmpID" type="text" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Enter First Name <span class="required"> * </span> </label>
<div class="col-md-7">
<input id="UserEmpFirstName" type="text" class="form-control"/>
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Enter Middle Name </label>
<div class="col-md-7">
<input id="UserEmpMiddleName" type="text" class="form-control"/>
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Enter Last Name <span class="required"> * </span> </label>
<div class="col-md-7">
<input id="UserEmpLastName" type="text" class="form-control"/>
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Enter Mobile Number <span class="required"> * </span> </label>
<div class="col-md-7">
<input id="UserEmpMobileNo" type="text" class="form-control allownumericwithoutdecimal"/>
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Enter Email Id <span class="required"> * </span> </label>
<div class="col-md-7">
<input id="UserEmpEmail" type="Email" class="form-control"/>
</div>
</div>
<div class="form-group">
<label class="label1 col-md-4">Select the applicable user role & privileges <span class="required"> * </span> </label>
<div class="col-md-7">
<textarea type="textarea" rowspan="5"> </textarea>
</div>
</div>
<div class="form-group">
<button class="btn btn-primary" id="SubmitUserRole" type="button" disabled="disabled">submit User</button>
</div>
</form>
<强> SCRIPT 强>
$(function(){
$('body').on('keyup change','#userRoleForm input, #userRoleForm select',function(){
var UserCampusName = $('#UserCampus').val()
var EmpID = $('#UserEmpID').val()
var FirstName = $('#UserEmpFirstName').val()
var LastName = $('#UserEmpLastName').val()
var mobileNo = $('#UserEmpMobileNo').val()
var EmpEmail = $('#UserEmpEmail').val()
if ((FirstName.length > 0) && (LastName.length > 0) && (mobileNo.length > 0) && (EmpEmail.length > 0) && (EmpID.length > 0) && (UserCampusName != 0)) {
console.log('up')
$('#SubmitUserRole').removeAttr('disabled');
}
else {
console.log('down')
$('#SubmitUserRole').attr('disabled', 'disabled');
}
})
})
您可以在if-else
中查看尽可能多的输入。在上面的代码中,我没有检查textarea验证,但你可以相应地修改它。