JBTALKS.CC

标题: 怎样set focus? [打印本页]

作者: nic58191    时间: 2010-9-18 02:52 PM
标题: 怎样set focus?
我检查顾客的nric是否只有一个而已,如果发现已经在系统里
就会popup alert
我要怎样set focus呢?
  1. if ( ! checkUnique('user_new_nric', $_POST['user_new_nric']) )
  2.                 {
  3.                         echo '<script = "JAVASCRIPT">alert("The new NRIC you used is associated with another user. Please try again!")
  4.                         </script>';
  5.                 }
复制代码

作者: wewanwang    时间: 2010-9-18 07:48 PM
试试这个:
echo '<script = "JAVASCRIPT">alert("The new NRIC you used is associated with another user. Please try again!");
document.yourform.fieldname.focus();
</script>';

作者: nic58191    时间: 2010-9-19 04:02 PM
回复 2# wewanwang

Error:'document.subAgent.user_new_nric' is null or not an object
作者: clown09    时间: 2010-9-19 10:32 PM
if ( ! checkUnique('user_new_nric', $_POST['user_new_nric']) )
                {
                        echo '<script = "JAVASCRIPT">alert("The new NRIC you used is associated with another user. Please try again!")
                        </script>';
                }


请在user_new_nric的input 加上 id, eg:
<input type="text" name="user_new_nric" id="user_new_nric" value="" />
Javascript 部分:
<script type="text/javascript">
document.getElementById("user_new_nric").focus();
</script>. 请把这部分的code放置在<input type="user_new_nric" />出现之后。Error:'document.subAgent.user_new_nric' is null or not an object 的问题是因为你在<input />之前,放入<script>,这样js 这么可能找到<input />?




欢迎光临 JBTALKS.CC (https://jbtalks.my/) Powered by Discuz! X2.5