gpt4 book ai didi

javascript - Jquery 获取类 "nodeId"值

转载 作者:行者123 更新时间:2023-11-30 12:34:30 26 4
gpt4 key购买 nike

我想从字符串中获取值 117。但未能...

当我执行以下操作时,

$(this)

我得到这样的“字符串”

"[Node: <span class='nodeId'>117</span>] <br>bla bla (bla/6)<br>Value: n.a."

进一步推导如下,

$(this).filter('.nodeId').html()

我收到错误...

Uncaught Error: Syntax error, unrecognized expression: [Node: <span class='nodeId'>117</span>] <br>bla bla (bla/6)<br>Value: n.a. 

要求的片段:

var onDeviceMarkerClick = function() {
var currentNodeIdVal = null;
var marker = this;
var markerLat = marker.getPosition().lat();
var markerLng = marker.getPosition().lng();

var checkStreetView = new google.maps.LatLng(markerLat,markerLng);
var svClient = new google.maps.StreetViewService();
var checkaround = 50;
svClient.getPanoramaByLocation(checkStreetView, checkaround, function (nearest) {
if (nearest !== null){
var nodeIdString = marker.title;
var checkThisVal = $(nodeIdString).filter('.nodeId').html();
console.log(checkThisVal); // Here I got the error

//More to go

有人吗?

最佳答案

如果 HTML 的 jQuery 格式不正确(例如,不是以 <> 元素开头),您需要先将其包装(例如,在虚拟 div 元素中)

JSFiddle:http://jsfiddle.net/TrueBlueAussie/vme0us9s/1/

var nodeIdString = marker.title;

// Create a new DIV and insert the content
var $div = $('<div>').html(nodeIdString);

var checkThisVal = $div.find('.nodeId').text();

alert(checkThisVal); // Alerts 117

关于javascript - Jquery 获取类 "nodeId"值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26525219/

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