// js函數實現中英文判斷處理
function tips(title, id)
{
var width = 40;
var xx = 0;
var returntitle = "";
for ( var i = 0; i < title.length; i++)
{
returntitle = returntitle + title.charAt(i);
if(isChina(title.charAt(i)))
{
xx = xx + 2;
}
else
{
xx = xx + 1;
}
if (parseInt(xx) > parseInt(width))
{
returntitle = returntitle + "/n";
xx = 0;
}
}
document.getElementById(id).title=returntitle;
}
function isChina(s)
{
var patrn = /[/u4E00-/u9FA5]|[/uFE30-/uFFA0]/gi;
if (!patrn.exec(s))
{
return false;
}
else
{
return true;
}
}
// 舉例頁面
<span title="${test }" id="titleid">${test }</span>
// 頁面最底部調用下面的事件
// title 表示要tips中要顯示的內容
// id表示要顯示tips要顯示的內容的id標識
<script>
tips("${test }", titleid);
</script>