简体   繁体   English

JQuery:将焦点设置在特定页面上的输入字段上

[英]JQuery: setting focus on an input field on a specific page

I am trying to set focus on Customer Name only on the search_orders.php page.我试图仅在 search_orders.php 页面上将焦点设置在客户名称上。 The code below is supposed to put the cursor in the Name input if on the order search page.如果在订单搜索页面上,下面的代码应该将光标放在名称输入中。 Somehow this doesn't work.不知何故,这不起作用。 Please suggest any change to my code that will fix this.请建议对我的代码进行任何更改以解决此问题。 Attached is the UI for searching orders, where I need the focus set on Customer Name.附件是用于搜索订单的用户界面,我需要将焦点设置在客户名称上。

在此处输入图片说明

function po_number_first(){
   if (document.location.href.indexOf("search_orders")==-1){
      document.search_form.po_number.focus();
}else{
     document.getElementById("Name").focus();
}
}

The function call is in a smartyTemplate files as seen in the code below.函数调用位于 smartyTemplate 文件中,如下面的代码所示。

{include file="header.tpl" page_name=Search extra_javascript='<script language="JavaScript" src="includes/search_orders.js"></script>' on_load_script='po_number_first()'}

Instead of adding it inside a function please try:-不要将其添加到函数中,请尝试:-

jQuery(document).ready(function() {
   if ( window.location.href.indexOf('/search_orders') > -1 ) {
     jQuery( "#target" ).focus();
   }else{
     jQuery( "#Name" ).focus();
   }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM