我按照这个解决方案,了解如何在外面点击任何地方时关闭Bootstrap Popover, https://stackoverflow.com/a/14857326/1005607
$('body').on('click', function (e) {
//only buttons
if ($(e.target).data('toggle') !== 'popover'
&& $(e.target).parents('.popover.in').length === 0) {
$('[data-toggle="popover"]').popover('hide');
}
});
但是有些东西仍然不起作用,我的JSFiddle: https://jsfiddle.net/m2k0wgys/3/
在这个JSFiddle中,单击外部并不关闭Popover。我的弹出窗口嵌套在A-links中。样本格式:
<a href="..>
<input type="image" src="info.png" data-toggle="popover" data-content=".." />
</a>
答案 0 :(得分:0)
我设法通过将以下代码行添加到img标记
来解决它data-trigger="focus" role="button" tabindex="0"
也不需要上面的机身点击js代码。删除可以编码的代码,它应该可以正常工作。
上述代码的引用可在此处的文档https://getbootstrap.com/docs/3.3/javascript/#popovers
中找到希望这有帮助,如果有任何疑问,请告诉我。
答案 1 :(得分:0)
仅适用于包含文字的按钮:
import cv2,os
import numpy as np
from PIL import Image
recognizer = cv2.face.createLBPHFaceRecognizer()
detector= cv2.CascadeClassifier("haarcascade_frontalface_default.xml");
def getImagesAndLabels(path):
#get the path of all the files in the folder
imagePaths=[os.path.join(path,f) for f in os.listdir(path)]
#create empth face list
faceSamples=[]
#create empty ID list
Ids=[]
#now looping through all the image paths and loading the Ids and the images
for imagePath in imagePaths:
#loading the image and converting it to gray scale
pilImage=Image.open(imagePath).convert('L')
#Now we are converting the PIL image into numpy array
imageNp=np.array(pilImage,'uint8')
#getting the Id from the image
Id=int(os.path.split(imagePath)[-1].split(".")[1])
# extract the face from the training image sample
faces=detector.detectMultiScale(imageNp)
#If a face is there then append that in the list as well as Id of it
for (x,y,w,h) in faces:
faceSamples.append(imageNp[y:y+h,x:x+w])
Ids.append(Id)
return faceSamples,Ids
faces,Ids = getImagesAndLabels('trainingImage')
recognizer.train(faces, np.array(Ids))
recognizer.save('trainer/trainer.yml')
});