我有以下代表一串html元素的Javascript代码:
html = '<tr>' +
'<td class="editMap" data-mode="option" data-wsid="'+row.option_id+
'" data-map="'+row.mapping_id+'" id="option-'+row.option_id+'">'+
'<span title="Options Mapping" data-toggle="popover" data-placement="left"style="cursor:pointer;">'+value+
'</span></td>'+'</tr>';
html变量实际上在循环中。我也有弹出代码,显示特定div的详细信息
$('[data-toggle="popover"]').popover({
html: true,
container: body,
content: function() {
return $('#popover-content').html();
}
});
<div id="popover-content" class="row" style="display:none;">
<input class="btn btn-xs btn-info" type="submit" value="Yes" style="display: inline-block; vertical-align: top;"/>
<input class="btn btn-xs btn-primary" type="submit" value="No" style="display: inline-block; vertical-align: top;"/>
</div>
我想要的是实际获取被弹出的元素的id,在这种情况下由“option - '+ row.option_id +'”表示。我尝试过以下但似乎无法正常工作:
$('[data-toggle="popover"]').each( function() {
$(this).popover({
html : true,
content: this.id,
console.log(this.id);
});
});
请帮助我获取身份证明。这可能是一个基本的问题,但我是Javascript的新手
答案 0 :(得分:1)
您需要使用this
而不是$('[data-toggle="popover"]').each( function() {
//try doing console log out of popover.
console.log($(this).attr('id'));
$(this).popover({
html : true,
content: $(this).attr('id')
});
});
来访问当前元素。
let videoSource = self.pcFactory.avFoundationVideoSource(with: nil)
let videoTrack = self.pcFactory.videoTrack(with: sVideoSource, trackId: "video0")
//setting the capture session to my RTCCameraPreviewView:
(self.previewView as! RTCCameraPreviewView).captureSession = (videoTrack.source as! RTCAVFoundationVideoSource).captureSession
stream = self.pcFactory.mediaStream(withStreamId: "unique_label")
audioTrack = self.pcFactory.audioTrack(withTrackId: "audio0")
stream.addAudioTrack(audioTrack)
var device: AVCaptureDevice?
for captureDevice in AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo) {
if (captureDevice as AnyObject).position == AVCaptureDevicePosition.front {
device = captureDevice as? AVCaptureDevice
break
}
}
if device != nil && videoTrack != nil {
stream.addVideoTrack(videoTrack)
}
configuration = RTCConfiguration()
configuration.iceServers = iceServers
peerConnection = self.pcFactory.peerConnection(with: configuration, constraints: RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints: ["DtlsSrtpKeyAgreement": "true"]), delegate: self)
peerConnection.add(stream)
答案 1 :(得分:0)
$()
是jQuery构造函数。
this
是对DOM调用元素的引用。
在$(this)
中,您只是将this
中的$()
作为参数传递,以便您可以调用jQuery方法和函数。
因此,您的代码将如下所示:
$('[data-toggle="popover"]').each( function() {
$(this).popover({
html : true,
content: $(this).attr('id'),
console.log(this.id);
});
});