Jquery代码未在测试站点上运行[重复]

问题描述 投票:2回答:2

这个问题在这里已有答案:

以下是我专注的代码示例。我试图将它与我的测试网站合并,但代码不起作用。我不明白为什么,在这两种情况下我都在使用最新版本的Jquery(1.5)我在我的测试网站上使用Google托管的Api。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>

<script>
  $('#name-label').dblclick(function() {
    $("#name").val('some text');
  });
</script>

<div class="ctrlHolder">
  <label for="" id="name-label">Name</label>
  <input name="name" id="name" type="text" class="textInput small" />
  <p class="formHint">The name of the item you are submitting</p>
</div>
javascript jquery
2个回答
4
投票

将它包装在$(document).ready(function() {});中吗?

$(document).ready(function() {
    $('#name-label').dblclick(function(){
        $("#name").val('some text');
    });
});

-1
投票
$(function() {
  $('#name-label').dblclick(function(){
      $("#name").val('some text');
  });
}
© www.soinside.com 2019 - 2024. All rights reserved.