Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery resize函数没有';行不通_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript jquery resize函数没有';行不通

Javascript jquery resize函数没有';行不通,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我不确定我错过了什么,我确定它以前工作过:-( 但我看不出问题所在 我需要我的函数wrapContent可以调整大小 当800时,应像以前一样返回 var$window=$(window); var windowsize=$window.width(); var body=$('html,body'); 函数wrapContent(){ 如果(窗口大小

我不确定我错过了什么,我确定它以前工作过:-( 但我看不出问题所在

我需要我的函数
wrapContent
可以调整大小

  • 当<800px时,该函数应将我的范围转换为选择选项标记
  • 当>800时,应像以前一样返回

var$window=$(window);

var windowsize=$window.width(); var body=$('html,body'); 函数wrapContent(){ 如果(窗口大小<800){ $('.pick country>span').replaceWith(函数(){ 返回$('').text($(this.text()).attr('value',$(this.data('id')); }); var select=$('.pick country>option')。wrapAll(''); } } wrapContent(); $(窗口)。调整大小(wrapContent); $('select.country list')。打开(“更改”,函数(){ if($(this.val()){ 使有生气({ scrollTop:$('#'+$(this.val()).offset().top-63 }“慢”); } }); $('.hotspot')。打开(“单击”,函数(e){ e、 预防默认值(); 使有生气({ scrollTop:$('#'+$(this).data('id')).offset().top-63 }“慢”); });

选择一个国家
伦敦
开普敦
北京
东京
香港
吉隆坡
新加坡
孟买
上海
悉尼
圣彼得堡
圣保罗
旧金山
达拉斯
纽约
迪拜
伦敦



开普敦


北京


东京


香港


吉隆坡


新加坡


孟买


上海


悉尼


圣彼得堡


圣保罗


旧金山


达拉斯


纽约


迪拜
改变这一点:

if (windowsize < 800) {

没错,但这不是主要问题。跨度被替换为div和一些break标记?看var windowsize=$window.width();我已经有了一个变量!!(它位于错误的位置,应该在
wrapContent()函数中)哦,我明白了,谢谢,但是为什么“调整大小”不能返回默认html?@Jai为什么我失去了“调整大小”按钮?
if ($window.width() < 800) {
var $window = $(window);
var windowsize = $window.width();
var body = $('html, body');
var spans = $('.pick-country').html(); //<----cache it here

function wrapContent() {
  if ($window.width() < 800) {
    $('.pick-country > span').replaceWith(function() {
      return $('<option/>').text($(this).text()).attr('value', $(this).data('id'));
    });
    var select = $('.pick-country > option').wrapAll('<select class="country-list"></select>');

  } else {
    $('.pick-country').html(spans); // replace the old content here
  }
}