javascript - 如何在div标签内获取跨度内部文本
问题描述
我在共享点页面中嵌入了 powerapps 表单。我在 powerapps 中有一个下拉框。在基于下拉值的共享点页面中,我想显示一些代码。从下面的代码我想要 APAC 文本。这里这个html代码是在浏览器中动态生成的。
这是我在浏览器中生成的 HTML 代码。
<div data-is-focusable="true" id="react-combobox-view-0" class="label_kohvda-o_O-label_2lsolt" tabindex="9" role="listbox" aria-expanded="false" aria-haspopup="true" aria-atomic="true" title="Region" aria-live="assertive">
<div style="width: 100%; overflow: hidden; position: relative; display: flex; height: 100%; align-items: stretch;">
<ul style="margin: 0px; padding: 5px; list-style: none; display: flex; overflow: hidden;">
<li class="selectedItem_1og5q2j">
<span class="topTagText_yz2uri-o_O-topTagText_t9v74o-o_O-topTagTextReadonly_ps5463">APAC</span></li></ul></div>
<div class="combobox-view-chevron arrowContainer_1kmq8gc-o_O-container_r2h174-o_O-containerColors_1803dea"></div></div>
解决方案
我们可以使用jQuery来实现它。
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var region=$("div[title='Region'] li[class^='selectedItem']").text();
alert(region);
});
</script>
或者
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
var myVar;
$(function () {
myVar = setInterval(getDropdownValue, 100);
});
function getDropdownValue(){
if($("div[title='Region'] li[class^='selectedItem']").length>0){
var region=$("div[title='Region'] li[class^='selectedItem']").text();
alert(region);
clearInterval(myVar);
}
}
</script>
推荐阅读
- python - 如何在matplotlib中修改数字堆叠在一起的x轴
- python - 在 Pandas 的时间戳中计算特定帧内出现的次数
- javascript - 如何在 html 的另一个组件中使用导出的函数?角度?
- bitmap - 这些 BMP(8 位,未压缩)字节是什么?
- python - Python - 如何使用 websocket-client 发送心跳?
- android - 我无法为 AMD 处理器安装 Android Emulator Hypervisor Driver
- algorithm - 堆排序策略:基于选择还是交换?
- r - h2o GLM R 色散参数
- python - Statsmodels AutoRegression 回测代码有效性
- django - 如何过滤指向自身的外键