我需要将一些数据存储在div和元标记中。
这里是div:
<div id="qtip-0" class="qtip simcal-default-calendar simcal-event-bubble qtip-pos-tc qtip-fixed qtip-focus" tracking="false" role="alert" aria-live="polite" aria-atomic="false" aria-describedby="qtip-0-content" aria-hidden="false" data-qtip-id="0" >
<div class="qtip-tip">
<canvas width="16" height="16" style="background-color: transparent !important; border: 0px !important; width: 8px; height: 8px;"></canvas>
</div>
<div class="qtip-content" id="qtip-0-content" aria-atomic="true">
<div class="simcal-event-details simcal-tooltip-content" style="display: block; visibility: visible;">
<div class="col-xs-12 title-event-container">
<span class="simcal-event-title" itemprop="name">Riunione intenra Scali ferroviari</span>
</div>
<p><label>Luogo:</label><br>
<span class="simcal-event-address simcal-event-start-location" itemprop="location" itemscope="" itemtype="http://schema.org/Place"><meta itemprop="name" content="Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia"><meta itemprop="address" content="Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia">Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia</span></p>
<div id="map">Mappa</div>
<p>
<a href="//maps.google.com?q=Palazzo+Marino+-+Comune+di+MilanoPiazza+della+Scala+2%2C+20121+Milano%2C+Italia" target="_blank">Vedi mappa ingrandita</a>
</p>
</div>
</div>
我需要访问:
<meta itemprop="address" content="Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia">
获取content
属性。
我在这里尝试过:
var currentEventAddress = $('#qtip-0 span').find('meta[itemprop="address"]').attr('content');
console.log(currentEventAddress);
但我得到undefined
答案 0 :(得分:0)
var currentEventAddress = $('#qtip-0').find('meta[itemprop="address"]').attr('content');
console.log(currentEventAddress);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="qtip-0" class="qtip simcal-default-calendar simcal-event-bubble qtip-pos-tc qtip-fixed qtip-focus" tracking="false" role="alert" aria-live="polite" aria-atomic="false" aria-describedby="qtip-0-content" aria-hidden="false" data-qtip-id="0">
<div class="qtip-tip">
<canvas width="16" height="16" style="background-color: transparent !important; border: 0px !important; width: 8px; height: 8px;"></canvas>
</div>
<div class="qtip-content" id="qtip-0-content" aria-atomic="true">
<div class="simcal-event-details simcal-tooltip-content" style="display: block; visibility: visible;">
<div class="col-xs-12 title-event-container">
<span class="simcal-event-title" itemprop="name">Riunione intenra Scali ferroviari</span>
</div>
<p><label>Luogo:</label><br>
<span class="simcal-event-address simcal-event-start-location" itemprop="location" itemscope="" itemtype="http://schema.org/Place"><meta itemprop="name" content="Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia"><meta itemprop="address" content="Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia">Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia</span></p>
<div id="map">Mappa</div>
<p>
<a href="//maps.google.com?q=Palazzo+Marino+-+Comune+di+MilanoPiazza+della+Scala+2%2C+20121+Milano%2C+Italia" target="_blank">Vedi mappa ingrandita</a>
</p>
</div>
</div>
&#13;
如果您想添加范围使用$('#qtip-0').find('meta[itemprop="address"]').attr('content')
$('#qtip-0 span.simcal-event-address')
因为包含元的跨度是类simcal-event-address
var currentEventAddress = $('#qtip-0 span.simcal-event-address').find('meta[itemprop="address"]').attr('content');
console.log(currentEventAddress);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="qtip-0" class="qtip simcal-default-calendar simcal-event-bubble qtip-pos-tc qtip-fixed qtip-focus" tracking="false" role="alert" aria-live="polite" aria-atomic="false" aria-describedby="qtip-0-content" aria-hidden="false" data-qtip-id="0">
<div class="qtip-tip">
<canvas width="16" height="16" style="background-color: transparent !important; border: 0px !important; width: 8px; height: 8px;"></canvas>
</div>
<div class="qtip-content" id="qtip-0-content" aria-atomic="true">
<div class="simcal-event-details simcal-tooltip-content" style="display: block; visibility: visible;">
<div class="col-xs-12 title-event-container">
<span class="simcal-event-title" itemprop="name">Riunione intenra Scali ferroviari</span>
</div>
<p><label>Luogo:</label><br>
<span class="simcal-event-address simcal-event-start-location" itemprop="location" itemscope="" itemtype="http://schema.org/Place"><meta itemprop="name" content="Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia"><meta itemprop="address" content="Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia">Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia</span></p>
<div id="map">Mappa</div>
<p>
<a href="//maps.google.com?q=Palazzo+Marino+-+Comune+di+MilanoPiazza+della+Scala+2%2C+20121+Milano%2C+Italia" target="_blank">Vedi mappa ingrandita</a>
</p>
</div>
</div>
&#13;
答案 1 :(得分:0)
直接查找meta
标记及其attr
内容。
var currentEventAddress = $('#qtip-0 span').find('meta').attr('content');
alert(currentEventAddress)
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="qtip-0" class="qtip simcal-default-calendar simcal-event-bubble qtip-pos-tc qtip-fixed qtip-focus" tracking="false" role="alert" aria-live="polite" aria-atomic="false" aria-describedby="qtip-0-content" aria-hidden="false" data-qtip-id="0">
<div class="qtip-tip">
<canvas width="16" height="16" style="background-color: transparent !important; border: 0px !important; width: 8px; height: 8px;"></canvas>
</div>
<div class="qtip-content" id="qtip-0-content" aria-atomic="true">
<div class="simcal-event-details simcal-tooltip-content" style="display: block; visibility: visible;">
<div class="col-xs-12 title-event-container">
<span class="simcal-event-title" itemprop="name">Riunione intenra Scali ferroviari</span>
</div>
<p>
<label>Luogo:</label>
<br>
<span class="simcal-event-address simcal-event-start-location" itemprop="location" itemscope="" itemtype="http://schema.org/Place"><meta itemprop="name" content="Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia"><meta itemprop="address" content="Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia">Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia</span></p>
<div id="map">Mappa</div>
<p>
<a href="//maps.google.com?q=Palazzo+Marino+-+Comune+di+MilanoPiazza+della+Scala+2%2C+20121+Milano%2C+Italia" target="_blank">Vedi mappa ingrandita</a>
</p>
</div>
</div>
&#13;
答案 2 :(得分:0)
你不需要找。
像这样使用:
$(".btn").on("click", function() {
var currentEventAddress = $('meta[itemprop="address"]').attr('content');
alert(currentEventAddress)
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="btn">Get Meta</button>
<div id="qtip-0" class="qtip simcal-default-calendar simcal-event-bubble qtip-pos-tc qtip-fixed qtip-focus" tracking="false" role="alert" aria-live="polite" aria-atomic="false" aria-describedby="qtip-0-content" aria-hidden="false" data-qtip-id="0" >
<div class="qtip-tip">
<canvas width="16" height="16" style="background-color: transparent !important; border: 0px !important; width: 8px; height: 8px;"></canvas>
</div>
<div class="qtip-content" id="qtip-0-content" aria-atomic="true">
<div class="simcal-event-details simcal-tooltip-content" style="display: block; visibility: visible;">
<div class="col-xs-12 title-event-container">
<span class="simcal-event-title" itemprop="name">Riunione intenra Scali ferroviari</span>
</div>
<p><label>Luogo:</label><br>
<span class="simcal-event-address simcal-event-start-location" itemprop="location" itemscope="" itemtype="http://schema.org/Place"><meta itemprop="name" content="Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia"><meta itemprop="address" content="Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia">Palazzo Marino - Comune di Milano
Piazza della Scala 2, 20121 Milano, Italia</span></p>
<div id="map">Mappa</div>
<p>
<a href="//maps.google.com?q=Palazzo+Marino+-+Comune+di+MilanoPiazza+della+Scala+2%2C+20121+Milano%2C+Italia" target="_blank">Vedi mappa ingrandita</a>
</p>
</div>
</div>
&#13;
答案 3 :(得分:0)
这件事很简单。
<script type="text/javascript">
$(document).ready(function() {
console.log($("meta[itemprop='address']").attr("content"));
});
</script>