【问题标题】:javascript html placeholder errorjavascript html占位符错误
【发布时间】:2015-09-04 07:30:28
【问题描述】:

您好,我在 jsfiddle 上有以下代码

<label for="email">Kerko:</label>
<input class="form-control" type="text" name="kerkim" id="input_main">
<label for="name"> Vendi:</label>
<input type="text" class="form-control">


var placeholders = ['Elektricist','Hidraulik','Avokat','Doktor','Luleshites'];

(function cycle() {

    var placeholder = placeholders.shift();
    $('input_main').attr('placeholder',placeholder);
    placeholders.push(placeholder);
    setTimeout(cycle,2500);

})();     

http://jsfiddle.net/rcj3thcu/

有人可以帮我找出它为什么不起作用吗?

在我的本地主机中,两个输入都开始工作,这让我抓狂!

在我的本地主机中重要的是两个输入字段都运行 我有
&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"&gt;&lt;/script&gt;

编辑 缓存清除!!!有效!

【问题讨论】:

标签: javascript html autocomplete


【解决方案1】:

当你试图引用一个 id 时,你应该总是在它前面加上 #:

$('#input_main').attr('placeholder',placeholder);

除此之外,只需正确配置 JSFiddle(例如,包括 jQuery)。

http://jsfiddle.net/rcj3thcu/3/

【讨论】:

    【解决方案2】:

    您在input_main 之前缺少ID 选择器#

    $('#input_main').attr('placeholder',placeholder);
    

    另外,在您的 jsfiddle 中没有包含 jQuery。

    【讨论】:

      猜你喜欢
      • 2014-01-30
      • 1970-01-01
      • 1970-01-01
      • 2015-04-18
      • 1970-01-01
      • 1970-01-01
      • 2013-09-13
      • 2017-11-09
      • 2018-10-25
      相关资源
      最近更新 更多