2015-01-31 3 views
0

저는 자바 스크립트를 처음 사용했습니다. 나는 처음부터 처음으로 코드를 만들었고, 내가 한 것은 화면 너비가 900px에 도달 할 때 더 짧은 말씨로 바뀌 었다는 것입니다.브라우저를 다시로드 한 후 Javascript에서 텍스트 변경을 유지하는 방법은 무엇입니까?

다음은 타이틀 탭에서 다음과 같습니다 신용 대

신용 전문가는 우리가 작업을 수행 우리가

을 도울 방법 에 사람들 도움이 어떻게 점수
신용 전문가로 점수 그러나 브라우저의 크기를 조정하면 새로 고침 할 때 더 긴 단어로 되돌아갑니다. 그것을 상쾌하게 한 후에도 그것을 유지할 수있는 방법이 있습니까?

CSS 또는 미디어 쿼리을 사용할 수 없습니다. jQuery 탭을 사용하면 너비가 900px 미만인 것을 감지하면 더 긴 말씨를 제거 할 수 없기 때문에 사용할 수 없습니다. 이건 내 자바 스크립트 코드가 http://planet.nu/dev/test/index.html

입니다 :

는 웹 페이지입니다

$(document).ready(function(){ 
 
function checkWidth() { 
 
    if ($(window).width() < 900) { 
 
     $('li.cvc').text('Credit Expert vs Score'); 
 
     $('li.hwh').text('How we help'); 
 
    } else { 
 
     $('li.cvc').text('Credit Expert vs Credit Score'); 
 
     $('li.hwh').text('How we help people'); 
 
    } 
 
} 
 
$(window).resize(checkWidth); 
 
});

+0

[Web Storage API] (https://developer.mozilla.org/en/US/docs/Web/API/Web_Storage_API)를 확인하십시오. –

답변

0

당신은 페이지로드에있는 함수를 호출 할 triggerHandler를 사용할 수 있습니다.

$(window).resize(checkWidth).triggerHandler('resize'); 
0
페이지가 먼저 있도록로드 될 때 당신은 단지 checkWidth()를 호출 할 필요가

페이지 크기가 조정되기 전에 논리가 적용됩니다. 그래서 한 번 페이지로드에

$(document).ready(function(){ 
    function checkWidth() { 
     if ($(window).width() < 900) { 
      $('li.cvc').text('Credit Expert vs Score'); 
      $('li.hwh').text('How we help'); 
     } else { 
      $('li.cvc').text('Credit Expert vs Credit Score'); 
      $('li.hwh').text('How we help people'); 
     } 
    } 
    $(window).resize(checkWidth); 
    checkWidth(); 
}); 
0

실행 checkWidth는 :

$(window).resize(checkWidth); 
checkWidth(); 
0

그냥 checkWidth()를 호출하십시오. function like

$(document).ready(function(){ 
function checkWidth() { 
    if ($(window).width() < 900) { 
     $('li.cvc').text('Credit Expert vs Score'); 
     $('li.hwh').text('How we help'); 
    } else { 
     $('li.cvc').text('Credit Expert vs Credit Score'); 
     $('li.hwh').text('How we help people'); 
    } 
} 
$(window).resize(checkWidth); 
checkWidth(); 
});