IE8 및 9에서 자리 표시 자 특성을 지원하는 방법 지원되지 않습니다. 내 프로젝트 (ASP Net)에서이를 지원하는

작은 문제 placeholder가 있습니다 .IE 8-9에서 입력 상자 의 속성이 지원되지 않습니다.

내 프로젝트 (ASP Net)에서이를 지원하는 가장 좋은 방법은 무엇입니까? jQuery를 사용하고 있습니다. 다른 외부 도구를 사용해야합니까?

http://www.hagenburger.net/BLOG/HTML5-Input-Placeholder-Fix-With-jQuery.html는 좋은 솔루션?



답변

이 jQuery 플러그인을 사용할 수 있습니다 :
https://github.com/mathiasbynens/jquery-placeholder

그러나 귀하의 링크도 좋은 해결책 인 것 같습니다.


답변

다음 폴리 필 중 하나를 사용할 수 있습니다.

이 스크립트는 placeholder속성을 지원하지 않는 브라우저 에서 속성에 대한 지원을 추가 하며 jQuery가 필요하지 않습니다!


답변

$ .Browser.msie은 당신이 사용하는이 … 더 이상 최신 JQuery와에없는 $의 .support을

아래처럼 :

 <script>

     (function ($) {
         $.support.placeholder = ('placeholder' in document.createElement('input'));
     })(jQuery);


     //fix for IE7 and IE8
     $(function () {
         if (!$.support.placeholder) {
             $("[placeholder]").focus(function () {
                 if ($(this).val() == $(this).attr("placeholder")) $(this).val("");
             }).blur(function () {
                 if ($(this).val() == "") $(this).val($(this).attr("placeholder"));
             }).blur();

             $("[placeholder]").parents("form").submit(function () {
                 $(this).find('[placeholder]').each(function() {
                     if ($(this).val() == $(this).attr("placeholder")) {
                         $(this).val("");
                     }
                 });
             });
         }
     });
 </script>

답변

jquery를 사용하면 다음과 같이 할 수 있습니다. 이 사이트 에서 Jquery를 사용하는 자리 표시 자

$('[placeholder]').parents('form').submit(function() {
  $(this).find('[placeholder]').each(function() {
    var input = $(this);
    if (input.val() == input.attr('placeholder')) {
      input.val('');
    }
  })
});

이들은 대체 링크입니다

  1. 자리 표시 자 jquery 라이브러리
  2. HTML5 폴리 필 -자리 표시 자 섹션으로 이동

답변

내가 시도한 여러 플러그인과 호환성 문제가 있었는데 이것은 텍스트 입력에서 자리 표시자를 지원하는 가장 간단한 방법 인 것 같습니다.

function placeholders(){
    //On Focus
    $(":text").focus(function(){
        //Check to see if the user has modified the input, if not then remove the placeholder text
        if($(this).val() == $(this).attr("placeholder")){
            $(this).val("");
        }
    });

    //On Blur
    $(":text").blur(function(){
        //Check to see if the use has modified the input, if not then populate the placeholder back into the input
        if( $(this).val() == ""){
            $(this).val($(this).attr("placeholder"));
        }
    });
}

답변

$(function(){    
    if($.browser.msie && $.browser.version <= 9){
        $("[placeholder]").focus(function(){
            if($(this).val()==$(this).attr("placeholder")) $(this).val("");
        }).blur(function(){
            if($(this).val()=="") $(this).val($(this).attr("placeholder"));
        }).blur();

        $("[placeholder]").parents("form").submit(function() {
            $(this).find('[placeholder]').each(function() {
                if ($(this).val() == $(this).attr("placeholder")) {
                    $(this).val("");
                }
            })
        });
    }
});

이 시도


답변

나는 이것을 사용합니다 .Javascript 일뿐입니다.

단순히 값이있는 입력 요소가 있으며 사용자가 입력 요소를 클릭하면 값이없는 입력 요소로 변경됩니다.

CSS를 사용하여 텍스트의 색상을 쉽게 변경할 수 있습니다. 자리 표시 자의 색상은 id #IEinput의 색상이며 입력 한 텍스트의 색상은 id #email의 색상입니다. 하지 마십시오 자리 표시자를 지원하지 않는 IE의 버전, getElementsByClassName 중 하나를 지원하지 않기 때문에, getElementsByClassName을 사용!

원래 비밀번호 입력 유형을 텍스트로 설정하여 비밀번호 입력에 플레이스 홀더를 사용할 수 있습니다.

땜장이 : http://tinker.io/4f7c5/1-JSfiddle
서버가 다운되었습니다!

*내 하찮은 영어 실력에 죄송하다는 말씀을 드리고 싶습니다

자바 스크립트

function removeValue() {
    document.getElementById('mailcontainer')
        .innerHTML = "<input id=\"email\" type=\"text\" name=\"mail\">";
    document.getElementById('email').focus(); }

HTML

<span id="mailcontainer">
    <input id="IEinput" onfocus="removeValue()" type="text" name="mail" value="mail">
</span>