所以我在数据库中有几列配置为TINYINT
. 我在前端也有相同数量的复选框。
这是我的HTML,
<script type="text/x-handlebars" id="project">
<div class="row">
<div class="span6">
<div class="well well-small">
<p style="text-align: center">
You can create a new Project by filling this simple form.
</p>
<p style="text-align: center"> Project Name should be minimum 10 characters & There's no limit on
Project Description.
</p>
</div>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="projectname">Project Name: </label>
<div class="controls">
<input type="text" name="projectname" id="projectname" required
title="Project Name is Required!" pattern="[A-z ]{10,}"
placeholder="Enter Project Name"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="projectdesc">Project Description:</label>
<div class="controls">
<textarea rows="3" id="projectdesc" name="projectdesc" placeholder="Enter Project Desc"
required="Description Required"></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label">Roles:</label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="roles" id="script" value="false"> Script
</label>
<label class="checkbox">
<input type="checkbox" name="roles" id="design" value="false"> Design
</label>
<label class="checkbox">
<input type="checkbox" name="roles" id="writer" value="false"> Writer
</label>
<label class="checkbox">
<input type="checkbox" name="roles" id="storyboard" value="false"> Storyboard
</label>
<label class="checkbox">
<input type="checkbox" name="roles" id="workbook" value="false"> Workbook
</label>
<br>
<button class="btn"
{{action 'createNew'}}>Add Project</button>
</div>
</div>
</form>
</div>
</div>
</script>
这就是我正在做的,
function(event) {
$(":text, input[type='checkbox'], textarea").each(function() {
if ($(this).val() === "") {
alert("Empty Fields!");
event.preventDefault();
} else {
App.Project.createNew();
alert("Project Created");
event.preventDefault();
}
});
}
还有 Ajax POST,
dataString = {
'projectname' : $("#projectname").val(),
'projectdesc' : $("#projectdesc").val(),
'script' : $('input.roles[type="checkbox"]:checked', this).val()
};
console.log('check');
$.ajax({
type : "POST",
url : "http://ankur.local/users/createNewProject",
data : dataString,
dataType : "json",
success : function(data) {
console.log('success');
alert('');
}
});
return false;
您可以从我的代码中看到,我正在尝试获取要存储在数据库中的文本框的选中值,例如 0 或 1 或 True 或 False?此外,我希望有一个条件,即在给定的复选框中,至少应选中一个。
'script' : $('input.roles[type="checkbox"]:checked', this).val()
我怎样才能实现我的目标?