簡體   English   中英

JQuery:將焦點設置在特定頁面上的輸入字段上

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

我試圖僅在 search_orders.php 頁面上將焦點設置在客戶名稱上。 如果在訂單搜索頁面上,下面的代碼應該將光標放在名稱輸入中。 不知何故,這不起作用。 請建議對我的代碼進行任何更改以解決此問題。 附件是用於搜索訂單的用戶界面,我需要將焦點設置在客戶名稱上。

在此處輸入圖片說明

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

函數調用位於 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()'}

不要將其添加到函數中,請嘗試:-

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