谁能告诉我这个功能有什么问题?一切正常,直到我尝试更改标题属性,最后一行。它不会改变并具有原始价值。我使用标题attr作为鼠标悬停的通知
P.S。 Javascript / jQuery不是我的强项,我是一个C#开发人员,所以请你好。
function doAlerts(serverDateTime)
{
$('.alertText').each(function()
{
var getCell = $(this).find("td").eq(0).html()
var respCount = $(this).find(".messageCount").val();
var callerId = $(this).find(".messageCallerID").val();
var getTitleText = $(this).attr('title');
//get date and title from row off page
var createDate = $(this).find('.createdDate').html();
var titleText = $(this).attr('title').replace('Expected SLA : ', '').replace('Expected Response : ', '');
var title = "Ticket No : " + getCell + "<br>" + getTitleText.replace(' - ','<br>') + "<br>";
var slaResult = warning(titleText, serverDateTime, 20, "SLA");
var expResult = warning(titleText, serverDateTime, 60, "Exp");
if(slaResult)
{
$(this).addClass('warning');
$(".warning").css("background-color", "#FFdddd");
title = title + "<br>There is less than 20mins before expected 4 hour SLA.<br>";
}
if(expResult)
{
$(this).addClass('warning');
$(".warning").css("background-color", "#FFdddd");
title = title + "<br>There is less than 60mins before expected 24 hour response.<br>";
}
if(respCount)
{
if(respCount > 5)
{
$(this).addClass('warning');
$(".warning").css("background-color", "#FFdddd");
title = title + "<br>There has been " + respCount + "messages. A phone call is required to the client<br>";
}
}
$(this).attr("title", title);
});
}
答案 0 :(得分:1)
您不能在属性中使用html(<br>
)文本。只允许使用纯文本。
答案 1 :(得分:0)
如果您想在title属性中使用换行符,则需要使用CR / LF ASCII字符而不是<br />
元素。
答案 2 :(得分:0)
你可以通过一点点javascript来模仿PHP的htmlentities()
函数:
$(this).attr('title', htmlentities(title));
function htmlentities (string, quote_style) {
// http://kevin.vanzonneveld.net
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: nobbler
// + tweaked by: Jack
// + bugfixed by: Onno Marsman
// + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Brett Zamir (http://brett-zamir.me)
// + input by: Ratheous
// - depends on: get_html_translation_table
// * example 1: htmlentities('Kevin & van Zonneveld');
// * returns 1: 'Kevin & van Zonneveld'
// * example 2: htmlentities("foo'bar","ENT_QUOTES");
// * returns 2: 'foo'bar'
var hash_map = {}, symbol = '', tmp_str = '', entity = '';
tmp_str = string.toString();
if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {
return false;
}
hash_map["'"] = ''';
for (symbol in hash_map) {
entity = hash_map[symbol];
tmp_str = tmp_str.split(symbol).join(entity);
}
return tmp_str;
}
来源: http://github.com/kvz/phpjs/raw/master/functions/strings/htmlentities.js