gpt4 book ai didi

javascript - 使用javascript获取title属性

转载 作者:搜寻专家 更新时间:2023-10-31 08:24:54 24 4
gpt4 key购买 nike

enter image description here

我是 JavaScript 的新手,我正在从事一个使用面部识别来检测情绪的项目。面部识别部分正在检测情绪,但我需要访问由此产生的情绪。面部识别 API 不断反馈,结果在 "div"id= results 标签下不断变化

<div id="results" style="word-wrap:break-word;">
<span> Timestamp: 93.12 </span>
<br>
<span>Number of faces found: 1</span>
<br>
<span> Appearance: {"gender":"Male","glasses":"Yes","age":"25 - 34","ethnicity":"Black African"}</span><br><span>Emotions: {"joy":0,"sadness":0,"disgust":1,"contempt":0,"anger":0,"fear":0,"surprise":0,"valence":0,"engagement":0}
</span>
<br>
<span> Emoji:
<img class="chromoji" title="Neutral Face" alt=":neutral_face:" src="chrome-extension://cahedbegdkagmcjfolhdlechbkeaieki/images/apple/1f610.png"></span>
<br>
</div>

标题“Neutral Face”或alt是需要的主导情绪的属性之一

我尝试使用来自

的解决方案

Extract property of a tag in HTML using JavascriptHow to get title attribute from link within a class with javascript

在我的实际代码中

<div id="results" style="word-wrap:break-word;">
<script>
//var images = document.querySelectorAll('img');
var emotion = document.getElementByTagName("img")[0].getAttributes("title");
console.log(emotion)
</script>
</div>

我尝试在生成结果的 JS 文件中使用此片段中的最后两行代码:

detector.addEventListener("onImageResultsSuccess", function(faces, image, timestamp) {
$('#results').html("");
log('#results', "Timestamp: " + timestamp.toFixed(2));
log('#results', "Number of faces found: " + faces.length);
if (faces.length > 0) {
log('#results', "Appearance: " + JSON.stringify(faces[0].appearance));
log('#results', "Emotions: " + JSON.stringify(faces[0].emotions, function(key, val) {
return val.toFixed ? Number(val.toFixed(0)) : val;
}));
log('#results', "Emoji: " + faces[0].emojis.dominantEmoji);
drawFeaturePoints(image, faces[0].featurePoints);
var motion = faces[0].emojis.dominantEmoji;
log('#results', motion);
}
});

另外,我将此添加到需要情感识别反馈的 JavaScript 文件中

var tag = document.getElementByTagName("img")
var emotion= tag.getAttribute("title");
console.log(emotion);

同样在另一个单独的试验中,我在索引 html 文件中做了这个

<script type="text/javascript">
var image = document.getElementsByTagName("img")[0];
var title = image.getAttribute("title");
console.log(title); // shows the value of title for the element "image"
</script>

该项目的主要思想是检测用户的情绪并根据该情绪播放音乐

最佳答案

你可以试试这个:

<script type="text/javascript">
var image = document.getElementsByTagName("img")[0];
var title = image.getAttribute("title");

console.log(title); // shows the value of title for the element "image"
</script>

在此处查看演示:http://codepen.io/anon/pen/vyVQBJ

关于javascript - 使用javascript获取title属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41113577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com