如何使用jQuery在title属性中添加换行符 [英] How to add line break in title attribute using jquery

查看:216
本文介绍了如何使用jQuery在title属性中添加换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请在下面找到我的代码,该代码将有关鼠标悬停事件的工具提示添加到我的调查引擎中的某个字段. 我要实现的是在工具提示中添加换行符. 任何帮助,我们将不胜感激.

Please find my code below which adds a tooltip on mouseover event to a field in my survey engine. What I want to achieve is add line breaks to the tooltip. Any help is greatly appreciated.

var $j = jQuery.noConflict();

$j('#choice31QID405').mouseover(function() { 
$j(this).attr('title','My name is Glenn. <Add a line break>. I am a good boy'. <Add a line break>. I live in New Delhi); 
})

$j('#choice31QID405').mouseout(function() { 
$j(this).removeAttr('title'); 
})

推荐答案

在现代浏览器中,您只能使用换行符:

On modern browsers, you can just use a line break:

$("#target").attr("title", "Hello\nWorld");

<p title="Hello
World">
This one is hardcoded in the HTML.
</p>
<p id="target">
This one is added later
</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

在当前(截至本文撰写)Chrome和Firefox以及IE11上,该方法都可以正常工作.

That works fine on current (as of this writing) Chrome and Firefox, as well as IE11.

这篇关于如何使用jQuery在title属性中添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆