我试图获得特别点击的div的内部html内容,我有很多div元素。
看下面我使用的代码。
$(function() {
$( "#try" ).click(function() {
var clickedValue = $(this).find('div').text();
alert(clickedValue);
});
});Run Code Online (Sandbox Code Playgroud)
<div id="try">
<div class="cchoice" style="background-color: blue;">B</div>
<div class="cchoice" style="background-color: red;">R</div>
<div class="cchoice" style="background-color: yellow;">Y</div>
<div class="cchoice" style="background-color: black;">B</div>
<div class="cchoice" style="background-color: gray;">G</div>
<div class="cchoice" style="background-color: white;">W</div>
</div>Run Code Online (Sandbox Code Playgroud)
我想以某种方式做到这一点,即当单击具有蓝色背景色的div时出现B,但随后看来我的方式有问题。由于某些原因,我无法将id属性赋予这些div集,并且它们必须具有相同的类。
上面代码的问题是,当我单击6个div元素中的任何一个时,clickedvalue将为BRYBGW。
我是 javascript 新手,我需要这方面的帮助。我想以下面的格式将多个视频存储在 js 文件中。
这是videos.js 文件
<script>
videos {
monthly {
january
{
240 : 'linktojanuary240.mp4',
360 : 'linktojanuary360.mp4',
480 : 'linktojanuary480.mp4',
720 : 'linktojanuary720.mp4'
},
february
{
240 : 'linktofebruary240.mp4',
360 : 'linktofebruary360.mp4',
480 : 'linktofebruary480.mp4',
720 : 'linktofebruary720.mp4'
}
};
family {
children
{
240 : 'linktochildren240.mp4',
360 : 'linktochildren360.mp4',
480 : 'linktochildren480.mp4',
720 : 'linktochildren720.mp4'
},
parent
{
240 : 'linktoparent240.mp4',
360 : 'linktoparent360.mp4',
480 : 'linktoparent480.mp4',
720 : 'linktoparent720.mp4'
}
};
};
</script>Run Code Online (Sandbox Code Playgroud)
**这是index.html 文件** …