如何将HTML包含到可编辑占位符中

How to include HTML into jEditable placeholder?

本文关键字:编辑 占位符 包含 HTML      更新时间:2023-09-26

我想有一个可编辑的占位符具有独特的风格,所以我试图包括简单的spanplaceholder属性,它看起来像我预期的,然而,点击它的工作方式像默认值,但显示占位符的内容作为原始HTML代码在输入框:

$(function() {
     $(".testjedit").each(function() {
            var old_value = $(this).attr( 'data-default' );
            var ph = $(this).attr( 'data-placeholder' );
            $(this).editable("http://localhost/index.php/welcome/update_record", { 
              "callback": function( value, settings ) {                              
                $( this ).attr('data-default', value );
              },
              "placeholder": "<span class='ph'>" + ph + "</span>",
              "submitdata": { 
                "oldvalue": old_value,
                "check": 1
              }
            }); 
     });
});

我把所有这些放到jsfiddle中,所以您可以使用它来看看哪里出错了。试着点击"评论"

在jEditable中似乎有一个小错误。你可以使用HTML作为占位符,但是不要在属性中使用单引号。

//  "placeholder": "<span class='ph'>" + ph + "</span>",
    "placeholder": '<span class="ph">' + ph + '</span>',

我已经更新了你的提琴:http://jsfiddle.net/8b8nH/10/

据我所知,匹配在这里失败了:

/* Remove placeholder text, replace is here because of IE. */
if ($(this).html().toLowerCase().replace(/(;|"|'/)/g, '') == 
    settings.placeholder.toLowerCase().replace(/(;|"|'/)/g, '')) {
       $(this).html('');
    }