我熟悉
HTML5& CSS3,刚开始学习JS.我需要帮助创建一个字符串变量列表,并将定义附加到所有这些变量.
基本上,我需要一个两列表,其中左列是字符串列表,当您单击单词时,它会拉出右侧的定义.我还需要确保在单击不同的单词时页面不会重新加载.
照片(下面的链接)最能说明我正在尝试创建的内容.
http://i.imgur.com/vaqXGpW.png?1
最佳答案 好吧,我想我得到了你想要的东西,它花了我一段时间.您现在唯一要做的就是编辑数组中的值以显示其他文本. (达美集团).
$(document).ready(function() {
var list = {
'Alfa': 'Alfa Text',
'Bravo': 'Bravo Text',
'Charlie': 'Charlie Text',
'Delta': 'Delta is the fourth letter of the Greek alphabet.<br/><br/>In the system of Greek numerals it has a value of 4.',
'Echo': 'Echo Text',
'Foxtrot': 'Foxtrot Text',
'Golf': 'Golf Text',
'Hotel': 'Hotel Text',
'India': 'India Text',
'Juliet': 'Juliet Text',
'Kilo': 'Kilo Text',
'Lima': 'Lima Text',
'Mike': 'Mike Text',
'November': 'November Text',
'Oscar': 'Oscar Text',
'Papa': 'Papa Text',
'Quebec': 'Quebec Text',
'Romeo': 'Romeo Text',
'Sierra': 'Sierra Text',
'Tango': 'Tango Text',
'Uniform': 'Uniform Text',
'Victor': 'Victor Text',
'Whiskey': 'Whiskey Text',
'X-ray': 'X-ray Text',
'Yankee': 'Yankee Text',
'Zulu': 'Zulu Text'
};
$.each(list, function(index, value) {
var listitem = $('<li></li>');
$('.letterlist').append(listitem.text(index));
});
$('.letterlist li').on('click', function() {
//Remove class from previous item
$('.selected').removeClass('selected');
//Add class to current item
$(this).addClass('selected');
var block = $('.block.right');
var descr = $('<p></p>');
var value = $(this).text();
//Empty header and content
block.children('h1').empty();
block.children('.content').empty();
//Add header and content
block.children('h1').text(value);
block.children('.content').append(descr.html(list[value]));
});
});
.block {
width: 250px;
height: 400px;
float: left;
font-family: Arial, sans-serif;
border: 3px solid #000;
overflow-y: auto;
}
.letterlist,
.letterlist li {
list-style: none;
padding: 0 20px;
}
.letterlist li.selected {
color: #f00;
background: #fac6c7;
}
.letterlist li:hover {
cursor: pointer;
}
.left {
font-size: 28px;
}
.content {
background: #fac6c7;
font-size: 20px;
margin: 10px 20px 20px;
padding: 16px 12px;
}
h1 {
text-transform: uppercase;
text-align: center;
margin: 10px 0 0 0;
}
p {
margin: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="block left">
<ul class="letterlist"></ul>
</div>
<div class="block right">
<h1></h1>
<div class="content">Select an item</div>
</div>