[英]Click on a div, take a text and copy paste it in a table
I have a plugin in my website and I want to customize a feature that it doesn't provide me. 我的网站上有一个插件,我想自定义一个它不提供给我的功能。
<div id="4_15:00" class="DOPBSPCalendar-hour dopbsp-available">
<div class="dopbsp-bind-top">
<div class="dopbsp-hour"> </div>
</div>
<div class="dopbsp-bind-middle dopbsp-group0">
<div class="dopbsp-hour">15:00</div>
<div class="dopbsp-available">1 available</div>
</div>
<div class="dopbsp-bind-bottom">
<div class="dopbsp-hour"> </div>
</div>
</div>
<div id="4_16:30" class="DOPBSPCalendar-hour dopbsp-available dopbsp-selected">
<div class="dopbsp-bind-top">
<div class="dopbsp-hour"> </div>
</div>
<div class="dopbsp-bind-middle dopbsp-group0">
<div class="dopbsp-hour">16:30</div>
<div class="dopbsp-available">1 available</div>
</div>
<div class="dopbsp-bind-bottom">
<div class="dopbsp-hour"> </div>
</div>
</div>
This is the part of the table I want to show the selected time under the date: 这是我希望在日期下显示所选时间的表格的一部分:
<table class="dopbsp-cart">
<tbody>
<tr>
<td class="dopbsp-label">Check in</td>
<td class="dopbsp-value">19 February 2015</td>
</tr>
And here is my jQuery: 这是我的jQuery:
<script>
jQuery(document).ready(function () {
jQuery('.DOPBSPCalendar-hour.dopbsp-available').click(function (e) {
t = jQuery('.dopbsp-selected .dopbsp-hour').text();
table = jQuery('table.dopbsp-cart .dopbsp-value');
table.first().append("<br>"+t)
});
});
</script>
When a user select a specific time, it automatically adds the class: dopbsp-selected
. 当用户选择特定时间时,它会自动添加类:
dopbsp-selected
。 So, I want to take the selected time and add it below the date. 所以,我想采取选定的时间并将其添加到日期下方。 However, I don't have any error on the console and I cannot find the reason that doesn't work.
但是,我在控制台上没有任何错误,我找不到不起作用的原因。
Your selectors are wrong: 你的选择器错了:
jQuery('.DOPBSPCalendar-hour .dopbsp-available').click(function (e) {
^---
The space means you want nested elements, the first having .DOBetc...
, and then a child element with .dobspetc...
. 空间意味着你要嵌套元素,第一个有
.DOBetc...
,然后一个子元素与.dobspetc...
。 Try 尝试
jQuery('.DOPBSPCalendar-hour.dopbsp-available').click(function (e) {
^--- no space
which indicates "any one element with these two classes applied". 表示“应用了这两个类的任何一个元素”。
The selector you are using is wrong. 您使用的选择器是错误的。
.DOPBSPCalendar-hour .dopbsp-available
The space
show that .dopbsp-available
is nested to .DOPBSPCalendar-hour
space
显示.dopbsp-available
嵌套到.DOPBSPCalendar-hour
But what you want is .DOPBSPCalendar-hour.dopbsp-available
但你想要的是
.DOPBSPCalendar-hour.dopbsp-available
which means a element
has both the classes
这意味着一个
element
具有两个classes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.