[英]What if I don't know whether an html element will be img or video?
I have a form with a file input. 我有一个带有文件输入的表格。 As each file is selected I add a preview of the image/video and a textarea for a caption.
选择每个文件后,我会添加图像/视频的预览和用于字幕的文本区域。
In order to display the preview, I need either: 为了显示预览,我需要:
Assuming you want to detect and then do something based on the element type, this jQuery should suffice. 假设您要检测然后根据元素类型执行某些操作,那么此jQuery就足够了。
var target = $('.media-element');
if ( target.is( "video" ) ) {
do something
}
else if ( target.is('img')){
do something else
}
else {return false;}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.