javascript - &#x00A0 并且无法在 iPad 上运行

标签 javascript jquery ipad

我的网站响应式导航菜单出现问题...当我检查 iPad 时,使用    的缩进不起作用.

el.find('a').each(function(){
    var $this = $(this),
    optText = "  " + $this.text(),
    optSub = $this.parents( '.' + settings.subMenuClass ),
    len = optSub.length,
    dash;
    ...

我尝试了 

if( $this.parents('ul ul ul').hasClass( settings.subMenuClass ) ) {
    dash = Array( len+1 ).join( settings.subMenuDash );
    optText = '    ' + optText;
}

 

if( $this.parents('ul ul ul').hasClass( settings.subMenuClass ) ) {
    dash = Array( len+1 ).join( settings.subMenuDash );
    optText = '&#x00A0 &#x00A0 ' + optText;
}

两者都无法在 iPad 上运行,但其他设备和浏览器都很棒。

有人知道我的情况吗?提前致谢...

最佳答案

您应该使用$(this).html()。由于    是 HTML 实体,因此如果将 optText 变量放入 中,它们将不会被解析元素的.text()

您必须使用 optText = $(this).html() 来读取它,并使用 $(this).html(optText) 来分配它:

function() ...
    var optText = $(this).html(); // read the text
    ...
    $(this).html('   ' + optText); // replace the text adding the indention
    ...

关于javascript - &#x00A0 并且无法在 iPad 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25129445/

相关文章:

javascript - Javascript/jQuery 中的范围?

javascript - 从外部 javascript 文件添加 html

javascript - HTML/Javascript Canvas - 如何在源点和目标点之间绘制图像?

javascript - 我如何用 Bacon.js 代替 Promise 表达初始过程?

javascript - 如何将 gwt 日期转换为 javascript 日期?

javascript - 如何使可调整大小的子 div 适合他的 parent

objective-c - 如何在 iCarousel 中使用 UIPageControl?

ios - 在 UIView 中使用 UIImagePickerController

ios - 在 UISplitView 中更改 RootViewController

javascript - 如何在两个 parent 之间转换一个div?