0

To explain this shortly, I have an mouseenter Jquery event firing up an AJAX call. And a Jquery UI tooltip.

$(function()
{
    $(document).tooltip({track:true});
    $('#NewUser').mouseenter(function(){AJAXValidation("NewUser")});
});  

Here is the call:

function AJAXValidation(section)
{
    var request = $.ajax(
    {
        url: "ProcessJRT.php",
        type: "POST",
        contentType:"application/x-www-form-urlencoded;charset=UTF-8",
        data:
        {
            validate:section
        }
    });

    request.done(
        function(message)
        {
            var div = document.createElement('div');
            $(div).html(message);
            $(div).children().each
            (
                function(i)
                {
                    var title = '';

                    if($('#' + $(this).attr('id')).attr('title') != null)
                    {
                        title = $('#' + $(this).id).attr('title');
                    }

                    title += $(this).html() + '\r\n';

                    $('#' + $(this).id).attr('title', title);
                }
            );
        });
}

What it does now is it take the <div>s from message and it place them in a parent <div>. (In my code the div already exist, I changed that part so the question would stay as short as possible).

I then take the text from those <div> and I want to place them in the corresponding <input/> title attribute.

Everything work just perfect here exepte this stupid little thing:

I am unable to add a LN or a CR in the title so all the texts from the divs would be on separate line...

I have tried adding a </br> inside the attribute like this:

function(i)
{
    var title = '';

    if($('#' + $(this).id).attr('title') != null)
    {
        title = $('#' + $(this).attr('id')).attr('title');
    }

    title += $(this).html() + '</br>';//<---See I added a BR here 

    $('#' + $(this).id).attr('title', title);
}

But it display the </br> as normal text. I than tried String.fromCharCode(13) but did'nt work, I tried jus '\n' or '\r\n' and still does work.

Can someone point out were I am derping on this one??

Thanks!

EDIT:

Changed the $('#' + $(this).attr('id')) to $('#' + $(this).id).

4

2 回答 2

1

以下是我使用@crush 给我的想法解决问题的方法:

第一的:

我从触发事件的函数中删除了工具提示初始化:

$(function()
{
    $('#NewUser').mouseenter(function(){AJAXValidation("NewUser")});
});

下一个:

我更改了“完成”功能,因此我每次都会使用 html 内容初始化一个新的工具提示(仅供参考 JQuery 工具提示可以格式化 HTML)

这是现在的样子:

function(message)
{
    var div = document.createElement('div');
    $(div).html(message);

    var title = '';

    $(div).children().each
    (
        function(i)
        {
            if($('#' + $(this).id).attr('title') != null)
            {
                title = $('#' + $(this).id).attr('title');
            }

            title += $(this).html() + '</br>';

            $(document).tooltip({content:title, items:('#' + $(this).id)});
        }
    );
}
于 2013-09-13T15:03:08.123 回答
1

您不能以这种方式格式化标题属性,它不起作用,并且在不同的浏览器中会有所不同。

试试 jquery 插件 qTip 来实现你想要的。(看起来也不错!) http://craigsworks.com/projects/qtip/

或者,您可以使用&nbsp;&nbsp;&nbsp;etc 作弊,将文本推送到下一行。但这充其量是片状的。

于 2013-09-13T14:14:55.877 回答