当最后一步需要从上一个函数获取信息时,我正在执行3步jQuery练习。前两个步骤有效。但是,我无法运行第三个函数。
第一步=用户从下拉菜单中选择一个类别 JavaScript:
var selectedCategory;
var textNameOfBusinessCategorySelected;
var nameOfBusinessesUnderCategory;
function businessListingResults(databaseList) {
selectedCategory = $("#select-business-listing option:selected").val();
textNameOfBusinessCategorySelected = $("#select-business-listing option:selected").text();
nameOfBusinessesUnderCategory = databaseList[selectedCategory];
for (findBusinessNamesUnderCategory in nameOfBusinessesUnderCategory) {
$("#listingResults").append("<li>" + findBusinessNamesUnderCategory + "</li>");
console.log(findBusinessNamesUnderCategory);
} // line ends for in loop
} // line closes function
HTML:
<h4 class="title">Select a Category from the drop down menu to check your local businesses</h4>
<select id="select-business-listing" name="submitted[select_your_program]" class="select-a-business">
<option value="musEnt">Music and Entertainment</option>
<option value="paint">Paint</option>
</select>
<br/>
<button class="listingsBtn" onclick="businessListingResults(businessListings)">Search Listings</button>
</div>
<p id="listingResults"></p>
第二步= ul列表中显示了类别下的企业,用户选择了企业 JavaSript:
function clickListingLink() {
// function is for when a link is clicked after list of businesses appear
$('#listOfBusinesses').on('click','li', function(){
console.log('you clicked me');
seeListingInfoTable();
$("hr").show();
});
}
第3步=一旦用户从ul列表中选择了一家公司,就会出现带有该公司信息的表格。这是我无法工作的部分。以下是该公司的表格,但是单击该公司后就不会出现。 JavaScript:
function seeListingInfoTable() {
var tbl = "";
tbl += '<table class="table table-hover">';
tbl += '</table>';
tbl += '<tbody>';
tbl += '<caption class="listingTitle">' + titleOfBusinessSelected + '</caption>';
tbl += '<tr>';
tbl += '<th>Address</th>';
tbl += '<th>Phone Number</th>';
tbl += '<th>Website</th>';
tbl += '<th>Specialty</th>';
tbl += '</tr>';
tbl += '<tr>';
tbl += '<td><div class="row_data" edit_type="click" col_name="fname">' + businessLinkSelected["Address"] + '</div></td>';
tbl += '<td><div class="row_data" edit_type="click" col_name="fname">' + businessLinkSelected["Phone Number"] + '</div></td>';
tbl += '<td><div class="row_data" edit_type="click" col_name="fname">' + businessLinkSelected["Website"] + '</div></td>';
tbl += '<td><div class="row_data" edit_type="click" col_name="fname">' + businessLinkSelected["Specialty"] + '</div></td>';
tbl += '</tr>';
tbl += '</tbody>';
tbl += '</table>';
$(document).find("#infoTable").html(tbl);
} // line ends seeListingInfoTable function
我不确定如何将变量连接到表函数,以便用户可以选择任何选项将信息显示在表中。