當我使用以下代碼時,我一直在獲取以下錯誤。任何幫助表示讚賞。我一直堅持這一點。JSON和jQuery搜索
tipuedrop.js:60遺漏的類型錯誤:無法讀取的不確定
function getTipuedrop($obj) {
if ($obj.val()) {
var c = 0;
for (var i = 0; i < tipuedrop_in.pages.length; i++) {
var pat = new RegExp($obj.val(), 'i');
if ((tipuedrop_in.pages[i].name.search(pat) != -1 || tipuedrop_in.pages[i].description.search(pat) != -1) && c < set.show) {
if (c == 0) {
var out = '<div class="tipue_drop_box"><div id="tipue_drop_wrapper">';
}
out += '<a href="' + tipuedrop_in.pages[i].name + '"';
if (set.newWindow) {
out += ' target="_blank"';
}
out += '><div class="tipue_drop_item"><div class="tipue_drop_left"><img src="' + tipuedrop_in.pages[i].name + '" class="tipue_drop_image"></div><div class="tipue_drop_right">' + tipuedrop_in.pages[i].name + '</div></div></a>';
c++;
}
}
if (c != 0) {
out += '</div></div>';
$('#tipue_drop_content').html(out);
$('#tipue_drop_content').fadeIn(set.speed);
}
} else {
$('#tipue_drop_content').fadeOut(set.speed);
}
}
財產「搜索」這裏是整個的Javascript:
(function($) {
$.fn.tipuedrop = function(options) {
var set = $.extend({
'show' : 3,
'speed' : 300,
'newWindow' : false,
'mode' : 'static',
'contentLocation' : 'tipuedrop/tipuedrop_content.json'
}, options);
return this.each(function() {
var tipuedrop_in = {
pages: []
};
$.ajaxSetup({
async: false
});
if (set.mode == 'json')
{
$.getJSON(set.contentLocation)
.done(function(json)
{
tipuedrop_in = $.extend({}, json);
});
}
if (set.mode == 'static')
{
tipuedrop_in = $.extend({}, tipuedrop);
}
$(this).keyup(function(event)
{
getTipuedrop($(this));
});
function getTipuedrop($obj)
{
if ($obj.val())
{
var c = 0;
for (var i = 0; i < tipuedrop_in.pages.length; i++)
{
var pat = new RegExp($obj.val(), 'i');
if ((tipuedrop_in.pages[i].name.search(pat) != -1 || tipuedrop_in.pages[i].description.search(pat) != -1) && c < set.show)
{
if (c == 0)
{
var out = '<div class="tipue_drop_box"><div id="tipue_drop_wrapper">';
}
out += '<a href="' + tipuedrop_in.pages[i].name + '"';
if (set.newWindow)
{
out += ' target="_blank"';
}
out += '><div class="tipue_drop_item"><div class="tipue_drop_left"><img src="' + tipuedrop_in.pages[i].master_image + '" class="tipue_drop_image"></div><div class="tipue_drop_right">' + tipuedrop_in.pages[i].name + '</div></div></a>';
c++;
console.log(tipuedrop_in.pages[i].name);
console.log(tipuedrop_in.pages[i].description);
}
}
if (c != 0)
{
out += '</div></div>';
$('#tipue_drop_content').html(out);
$('#tipue_drop_content').fadeIn(set.speed);
}
}
else
{
$('#tipue_drop_content').fadeOut(set.speed);
}
}
$('html').click(function()
{
$('#tipue_drop_content').fadeOut(set.speed);
});
});
};
})(jQuery);
'tipuedrop_in.pages [i] .name.search(pat)'中的搜索(pat)是什麼? – madalinivascu
它從我的JSON文件中提取。 –
並且這個'var pat = new RegExp($ obj.val(),'i');'它做了什麼? – madalinivascu