【问题标题】:Twitter bootstrap typeahead does not work properly with data-source attributeTwitter bootstrap typeahead 不能与 data-source 属性一起正常工作
【发布时间】:2013-03-28 15:18:14
【问题描述】:

为什么当我在data-source 属性中使用" 符号来表示字符串值时一切正常,但是当我使用' 来表示它们时,引导程序只识别第一个字符?

我知道在 c# 和许多其他语言中 "' 之间的区别是字符和字符串之间的区别,但我第一次看到它在 html 中被严格使用,如果是这样的话为什么JS没有任何错误。

<div class="container">
    <div class="hero-unit">
        <form>
            <div>
                <label>working typeahead</label>
                <input type="text" data-provide="typeahead" autocomplete="off" data-source='["hello","world"]' />
            </div>
            <div>
                <label>not working typeahead</label>
                <input type="text" data-provide="typeahead" autocomplete="off" data-source="['hello','world']" />
            </div>
        </form>
    </div>

见小提琴:http://jsfiddle.net/H4Qmh/4/

【问题讨论】:

    标签: twitter-bootstrap typeahead.js


    【解决方案1】:

    这很奇怪,但data-source=["hello", "world"] 有效,即使它看起来不像干净的 HTML。

    我想知道它是否被视为 JSON,在这种情况下,所有元素都必须用双引号括起来。见:How to pass an array into jQuery .data() attribute

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-11
    • 2014-06-23
    • 1970-01-01
    • 1970-01-01
    • 2015-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多