我正在使用$('input[type="text"]').val()
传递搜索字符串。
现在的要求是:
如果是一个空的搜索,则我想将空搜索作为值传递,而不是$('input[type="text"]').val()
同时,
如果不为空且有一个值,则我想使用$('input[type="text"]').val()
传递相同的值。
我所尝试的:
$(document).on('click','.fa.fa-search', function()
{
ga('create', {{ GA Property }}, 'auto');
ga('send', 'event', 'Search',
function blank ()
{
alert('hi');
var srchStr = $('input[type="text"]').val();
if(srchStr == '') { srchStr = "Blank Search"; }
},
window.location.href);
});
如何做呢?
($('input[type="text"]').val().trim().length > 0) ? $('input[type="text"]').val() : "Blank Search"
。 - Beginner