我最近发现了 oEmbed,它是“一种允许嵌入 URL 表示的格式”,基本上您输入您喜欢的 youtube 视频的 url,oEmbed 将在此页面中返回视频的嵌入代码。
我想让我的用户选择输入网址或在文本框中嵌入代码。如果是嵌入代码,它应该保持文本不变,但如果它是一个 url,它应该从 oEmbed 获取嵌入代码。
我的问题如下:如何识别用户是粘贴嵌入代码还是 url?
$(document).ready(function() {
$('#embedCode').bind('paste', function(e) {
// time out until the value has been pased to the textbox
setTimeout(function() {
var code = $('#embedCode').val();
var tagCount = 0;
// Identify embedded code here
if(tagCount == 0) {
alert('LINK');
}
else {
alert('EMBED');
}
}, 100);
});
});
我正在考虑添加一种方法来计算有效标签(例如对象和参数)的数量,但尝试这样做没有运气。
有任何想法吗?
谢谢