【发布时间】:2018-02-14 00:26:32
【问题描述】:
尝试为联系人列表实现创建功能。
我希望它以第一个问题要求“联系人类型”的方式运行,其中包含三个字段 - 个人、团队和公司。
通过选择其中一个字段,下面的字段会发生变化。个人会显示所有字段(姓名、公司、职务、电话、电子邮件、地址),而公司会要求不提供姓名/职务,而团队会要求不提供职务。所有这些字段+第一个问题已经是mysql中的行。
我不知道从哪里开始,它的语法应该如何工作以及如何将 javascript 合并到这个函数中?和建议?
干杯!
编辑:我的错。所以我已经把所有的字段都放下了。
<!DOCTYPE html>
<html>
<head>
<title>Create new contact</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<form method="post" class="form-horizontal col-md-6 col-md-offset-3">
<h2>Motoko Insurance Contacts</h2>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script>
$( document ).ready(function() {
listenForInputChanges();
})
function listenForInputChanges() {
$('#contactType >input').change(function(){
console.log('val is '+$(this).val())
switch($(this).val()) {
case 'individual':
$('#nameDiv').show();
$('#companyDiv').show();
$('#titleDiv').show();
$('#phoneDiv').show();
$('#emailDiv').show();
$('#addressDiv').show();
break;
case 'team':
$('#nameDiv').show();
$('#companyDiv').show();
$('#titleDiv').hide();
$('#phoneDiv').show();
$('#emailDiv').show();
$('#addressDiv').show();
break;
case 'company':
$('#nameDiv').hide();
$('#companyDiv').show();
$('#titleDiv').hide();
$('#phoneDiv').show();
$('#emailDiv').show();
$('#addressDiv').show();
break;
}
})
}
</script>
<div class="form-group">
<label for="input" class="col-sm-2 control-label">What type of contact are you adding?</label>
<div class="col-sm-10">
<input type="radio" name="Contact_type"
value="individual" > Individual
<input type="radio" name="Contact_type"
value="team"> Team
<input type="radio" name="Contact_type"
value="company"> Company</div>
</div>
<div class="form-group">
<label for="input1" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" name="name" class="form-control" id="input1" placeholder="Name"
/>
</div>
</div>
<div class="form-group">
<label for="input1" class="col-sm-2 control-label">Company</label>
<div class="col-sm-10">
<input type="text" name="comp" class="form-control" id="input1" placeholder="Company" />
</div>
</div>
<div class="form-group">
<label for="input1" class="col-sm-2 control-label">Title</label>
<div class="col-sm-10">
<input type="text" name="title" class="form-control" id="input1" placeholder="Title" />
</div>
</div>
<div class="form-group">
<label for="input1" class="col-sm-2 control-label">Phone</label>
<div class="col-sm-10">
<input type="int" name="urstel" class="form-control" id="input1" placeholder="Phone"
/>
</div>
</div>
<div class="form-group">
<label for="input1" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" name="email" class="form-control" id="input1" placeholder="E Mail" />
</div>
</div>
<div class="form-group">
<label for="input1" class="col-sm-2 control-label">Address</label>
<div class="col-sm-10">
<input type="text" name="location" class="form-control" id="input1" placeholder="Address" />
</div>
</div>
<input type="submit" class="btn btn-primary col-md-2 col-md-offset-10" value="submit" />
</form>
</div>
</div>
</body>
</html>
【问题讨论】:
-
我将开始创建一个包含所有可能字段的表单,并根据调用,使用 jQuery 或原始 JS 从 HTML 中隐藏 ome 或其他字段。无论如何,看看你的任何代码都会很有帮助......
-
这有点像免费的编码服务
-
@plonknimbuzz 我的错。我已经在字段、$createsql 等方面记录了所有内容。这只是选择联系人类型时字段消失的问题。有人告诉我 javascript 是必要的,但我真的不确定 :(
-
@AxelAmthor 代码在上面。所有非常标准的字段。目前所有功能。只需要在单选框被填充时能够改变字段的功能。
标签: javascript php crud contact