【问题标题】:Ruby on Rails: Javascript: How to grob focus when the text box appearsRuby on Rails:Javascript:文本框出现时如何获取焦点
【发布时间】:2023-03-17 15:31:01
【问题描述】:

所以,我有

<script type="text/javascript">
function grabFocus(){
    document.getElementByID("category_name").focus();
}
</script>
<div>
<h1>New category</h1>
<br/>
<% remote_form_for :category, @category, :url=>{:action=>'ajax_create'} do |f| %>
  <%= f.error_messages %>
  <%= f.hidden_field :object_type %>

  <p>
    <%= f.text_field :name, :label=>false %>
    <%= f.submit 'Create' %>
  </p>
<% end %>
<br/>
</div>

在我刚刚拥有之前

<script type="text/javascript">
    document.getElementByID("category_name").focus();
</script>

在文件的底部。
但其他网站建议我将其设为函数,并在 onLoad 中调用它......但我正在使用的部分(上面粘贴的整个内容)没有正文...... 我正在显示 facebox 使用的 iframe 中的部分内容...

想法?

【问题讨论】:

    标签: javascript ruby-on-rails erb


    【解决方案1】:

    知道了……

    它的 ID.. 不是 ID...

    可悲的错误。

    getElementById

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-03
      • 1970-01-01
      • 2018-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多