请问为什么我没有拼接URL还是能跳转到淘宝搜索我相应文本框的值呢?原理是什么?请老师按步骤分析下谢谢
来源:3-1 改写搜索框功能--搜索验证
Jyuloeng
2019-07-26 23:52:34


2回答
同学你好,
测试之后可以发现是跳转到了淘宝网,这里是因为在form标签action属性值写了淘宝网的链接:

会跳转到淘宝网站。因为input框中有一个name属性值为q,所以在输入框中输入的内容提交之后q后面会跟着内容,不需要拼接,默认是get方式。
js中url链接现在没有作用,还没有通过这个链接获取数据,可以继续往下面学习哦!
祝学习愉快!
Jyuloeng
提问者
2019-07-26
(function () {
'use strict';
function Search(elem, options){
this.elem = $(elem);
this.options= options;
this.$input = $('.search-inputbox');
this.$layer = $('.search-layer');
this.$form = $('.search-form');
this.elem.on('click','.search-btn',$.proxy(this.submit,this));
}
Search.DEFAULTS = {
autocomplete: true,
url:'https://suggest.taobao.com/sug?code=utf-8&_ksTS=1484204931352_18291&callback=jsonp18292&k=1&area=c2c&bucketid=6&q=',
css3: false,
js: false,
animation: 'fade'
};
Search.prototype.submit = function(){
if($.trim(this.$input.val()) === ''){
return false;
}
this.$form.submit();
};
Search.prototype.autocomplete = function(){
};
Search.prototype.getData = function(){
};
Search.prototype.showLayer = function(){
};
Search.prototype.hideLayer = function(){
};
$.fn.extend({
search:function(options){
return this.each(function(){
var search = $(this).data('search');
var option = $.extend({},Search.DEFAULTS,$(this).data(),options);
if(!search){
$(this).data('search',search = new Search(this,option));
}
if(typeof search[option] === 'function'){
search[option]();
}
});
}
});
})();而且我的search.js中我也没有写ajax的跨域。。怎么就自己使用ajax跨域了呢请问
相似问题