Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.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 在IE9中设置占位符att_Javascript_Jquery_Html_Asp.net - Fatal编程技术网

Javascript 在IE9中设置占位符att

Javascript 在IE9中设置占位符att,javascript,jquery,html,asp.net,Javascript,Jquery,Html,Asp.net,我有以下基于按钮单击运行的代码 function ClickYes() { $('#<%=txtMsg.ClientID%>').attr('placeholder', 'Tell me more'); } 函数ClickYes(){ $('#').attr('占位符','告诉我更多'); } 按钮声明为以下内容 <button type="button" class="com-yes-btn2 feedback-btn-grey empx

我有以下基于按钮单击运行的代码

 function ClickYes() {      
      $('#<%=txtMsg.ClientID%>').attr('placeholder', 'Tell me more');
    }
函数ClickYes(){
$('#').attr('占位符','告诉我更多');
}
按钮声明为以下内容

<button type="button" class="com-yes-btn2 feedback-btn-grey empx11b12" id="btnYes" onclick="javascript:ClickYes();">

</button>

问题是,我需要根据事件动态设置占位符att,在chrome和firefox中,行为是正确的,但在使用IE9占位符时,没有添加占位符属性

如何跨浏览器管理此功能


谢谢

据我所知,IE9不支持
占位符
属性,因此它在IE9中不起作用

因此,您可以尝试以下解决方法:

function ClickYes() {      
  if(navigator.userAgent.indexOf("MSIE") > 0){
     $('#<%=txtMsg.ClientID%>').val('Tell me more');
  }else{
     $('#<%=txtMsg.ClientID%>').attr('placeholder', 'Tell me more');
  }
}
函数ClickYes(){
if(navigator.userAgent.indexOf(“MSIE”)>0){
$('#').val('告诉我更多');
}否则{
$('#').attr('占位符','告诉我更多');
}
}

据我所知,IE9不支持
占位符
属性,因此它在IE9中不起作用

因此,您可以尝试以下解决方法:

function ClickYes() {      
  if(navigator.userAgent.indexOf("MSIE") > 0){
     $('#<%=txtMsg.ClientID%>').val('Tell me more');
  }else{
     $('#<%=txtMsg.ClientID%>').attr('placeholder', 'Tell me more');
  }
}
函数ClickYes(){
if(navigator.userAgent.indexOf(“MSIE”)>0){
$('#').val('告诉我更多');
}否则{
$('#').attr('占位符','告诉我更多');
}
}

IE9不支持
占位符
属性,您需要使用
模糊
聚焦
事件来模拟此功能

function ClickYes() {

    var element = $('#<%=txtMsg.ClientID%>');

    // default action (on moderns browsers) 
    var placeholder = function() {
        element.attr('placeholder', 'Tell me more');
    };

    if (navigator.appVersion.match(/MSIE [\d.]+/)) {
        // if MSIE: we override this function
        placeholder = function() {
            var placeholderText = 'Tell me more';
            element.val(placeholderText);
            element.blur(function(){
                $(this).val() == '' ? $(this).val(placeholderText) : false;
            });
            element.focus(function(){
                $(this).val() == placeholderText ? $(this).val('') : false;
            });
        };
    };

    placeholder(); // we call the created function
}
函数单击是(){
var元素=$('\35;');
//默认操作(在moderns浏览器上)
变量占位符=函数(){
attr('占位符','告诉我更多');
};
if(navigator.appVersion.match(/MSIE[\d.]+/){
//如果MSIE:我们重写这个函数
占位符=函数(){
var placeholder text='告诉我更多';
element.val(占位符文本);
element.blur(函数(){
$(this.val()=''?$(this.val)(占位符文本):false;
});
元素。焦点(函数(){
$(this.val()==占位符文本?$(this.val)(''):false;
});
};
};
占位符();//我们调用创建的函数
}

来源:

IE9不支持
占位符
属性,您需要使用
模糊
聚焦
事件来模拟此功能

function ClickYes() {

    var element = $('#<%=txtMsg.ClientID%>');

    // default action (on moderns browsers) 
    var placeholder = function() {
        element.attr('placeholder', 'Tell me more');
    };

    if (navigator.appVersion.match(/MSIE [\d.]+/)) {
        // if MSIE: we override this function
        placeholder = function() {
            var placeholderText = 'Tell me more';
            element.val(placeholderText);
            element.blur(function(){
                $(this).val() == '' ? $(this).val(placeholderText) : false;
            });
            element.focus(function(){
                $(this).val() == placeholderText ? $(this).val('') : false;
            });
        };
    };

    placeholder(); // we call the created function
}
函数单击是(){
变量元素=$(“#”);
//默认操作(在moderns浏览器上)
变量占位符=函数(){
attr('占位符','告诉我更多');
};
if(navigator.appVersion.match(/MSIE[\d.]+/){
//如果MSIE:我们重写这个函数
占位符=函数(){
var placeholder text='告诉我更多';
element.val(占位符文本);
element.blur(函数(){
$(this.val()=''?$(this.val)(占位符文本):false;
});
元素。焦点(函数(){
$(this.val()==占位符文本?$(this.val)(''):false;
});
};
};
占位符();//我们调用创建的函数
}
来源:

是,IE 9不支持占位符。但是您可以四处寻找一些替代方法,比如javascript,以非常容易地实现这一点

<input type="text" placeholder="test" value="placeholder text" 
onfocus="if (this.value=='placeholder text') this.value = ''" onblur="if (this.value=='') this.value = 'placeholder text'"/>
现在您需要处理
focus
blur
事件,使其像这样完成

function ClickYes() {      
      // for modern browsers
      $('#txtMsg').attr('placeholder', 'Tell me more');

      // for older browsers
      $('#txtMsg').val('Tell me more');
      $('#txtMsg').css('color','#CCC');
    }
 $(document).ready(function () {
    $("#txtMsg").focus(function () {
       if ($(this).val() == 'Tell me more') {
          $(this).val('');
          $(this).css('color', 'black');
       }
    });
    $("#txtMsg").blur(function () {
       if (!$(this).val()) {
          $(this).val('Tell me more');
          $('#txtMsg').css('color', '#CCC');
       }
    });
 });

IE 9不支持Yes占位符。但是您可以四处寻找一些替代方法,比如javascript,以非常容易地实现这一点

<input type="text" placeholder="test" value="placeholder text" 
onfocus="if (this.value=='placeholder text') this.value = ''" onblur="if (this.value=='') this.value = 'placeholder text'"/>
现在您需要处理
focus
blur
事件,使其像这样完成

function ClickYes() {      
      // for modern browsers
      $('#txtMsg').attr('placeholder', 'Tell me more');

      // for older browsers
      $('#txtMsg').val('Tell me more');
      $('#txtMsg').css('color','#CCC');
    }
 $(document).ready(function () {
    $("#txtMsg").focus(function () {
       if ($(this).val() == 'Tell me more') {
          $(this).val('');
          $(this).css('color', 'black');
       }
    });
    $("#txtMsg").blur(function () {
       if (!$(this).val()) {
          $(this).val('Tell me more');
          $('#txtMsg').css('color', '#CCC');
       }
    });
 });


我使用placeholder.js,它很容易使用:

您只能通过引用jquery和placeholder.js以及下面的代码来使用它

$('input, textarea').placeholder();

我使用placeholder.js,它很容易使用:

您只能通过引用jquery和placeholder.js以及下面的代码来使用它

$('input, textarea').placeholder();

IE9不支持
占位符
属性,但有一些变通方法。看看这个类似问题的答案:IE9不支持
占位符
属性,但有解决办法。看一看类似问题的答案: