Re: [問題] 抓游標所在位置的index
※ 引述《kalecgos0616 (.)》之銘言:
: 我要抓游標所在位置是input名字為test的第幾個,這數字要怎麼抓呢?
: 我現在這樣寫
: <input name='test' onfocus='ABC(this)'> 第0個
: <input name='test' onfocus='ABC(this)'> 第1個
: <script>
: ABC(n){
: alert(n.index);
: }
: </script>
: alert出來是的結果undefined
: 請問要怎麼樣我focus到第一個的時候就alert出0
: focus到第二個的時候就alert出1 呢?
<input name='test' onfocus='abc(0)'> 第0個
<input name='test' onfocus='abc(1)'> 第1個
<script type="text/javascript">
function abc(){
alert(arguments[0]);
}
</script>
第二種寫法
<form name="form2">
<input name="test2" title="0"> 第0個
<input name="test2" title="1"> 第1個
</form>
<script type="text/javascript">
var test2 = document.form2.test2;
for(var i=0, length=test2.length; i<length; i++)
test2[i].onfocus = abc2;
function abc2(){
alert(this.title);
}
</script>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.122.30.198
→
11/23 20:57, , 1F
11/23 20:57, 1F
→
11/23 22:46, , 2F
11/23 22:46, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Web_Design 近期熱門文章
PTT數位生活區 即時熱門文章