【问题标题】:How to change placeholder for an textarea?如何更改文本区域的占位符?
【发布时间】:2013-10-06 13:03:00
【问题描述】:

此代码提交一个表单并且它可以工作,除了更改 textarea id=message 的占位符

$('#submit').click(function(){
   $.post("mail.php", $("#contact").serialize(), function(response) {
   $('#message').attr('placeholder', response);
   $('#success').html(response);
   });
}); 

Firebug 没有错误。

【问题讨论】:

  • 你在清除textarea的值吗?如果元素有值或输入的文本,占位符文本将不会显示。
  • @vyx.ca,请问如何清除textarea

标签: jquery forms textarea placeholder attr


【解决方案1】:

使用.prop() 代替.attr()

$('#message').prop('placeholder', response);

阅读.prop() vs .attr()

【讨论】:

  • Tushar,好像不行。我之前尝试过`$('#message').text('');` 来清除文本区域 - 没有结果。
  • @SunSky 提醒response 你得到了什么?
【解决方案2】:

使用.prop() 代替.attr()

$('#message').prop('placeholder', response);

【讨论】:

    猜你喜欢
    • 2017-10-03
    • 2015-06-05
    • 2011-05-09
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 2015-10-25
    相关资源
    最近更新 更多