如果重要的话,它需要在IE中工作。这应该基于列表框中的选择来填充表格单元格。稍后,我会将照片更改为将照片添加到框中的HTML。
HTML:
<script src="garver_contact.js" type="text/javascript"></script>
<table class="table table-bordered table-striped">
<tr>
<th>
<select class="col1 selectTopic">
<option>Payroll</option>
<option>Tax</option>
<option>Accounts Payable</option>
</select>
</th>
</tr>
<tr>
<td class="col1 name"></td>
</tr>
<tr>
<td class="col1 photo"></td>
</tr>
<tr>
<td class="col1 email"></td>
</tr>
<tr>
<td class="col1 phone"></td>
</tr>
</table>
<script src="contact.js" type="text/javascript"></script>
使用Javascript:
data = {
"contacts":
{
"contact": [
{
"name": "Payroll",
"photo": "Emp 1 Photo",
"email": "emp1@gusa.com",
"phone": "4113834848"
},
{
"name": "Tax",
"photo": "Emp 2 Photo",
"email": "emp2@usa.com",
"phone": "4113834848"
},
{
"name": "Accounts Payable",
"photo": "Emp 3 Photo",
"email": "emp3@usa.com",
"phone": "4113834848"
},
]
}
}
$(".selectTopic").change(function () {
var jthis = $(this);
var whichCol;
if (jthis.hasClass("col1")) {
whichCol = "col1";
}
$.each(data.contacts.contact, function (i, v) {
if (v.name == jthis.val()) {
$("td." + whichCol + ".name").html(v.name);
$("td." + whichCol + ".photo").html(v.photo);
$("td." + whichCol + ".email").html(v.email);
$("td." + whichCol + ".phone").html(v.phone);
return;
}
});
});