2014-05-17 233 views
0

這是我的下拉菜單。代碼似乎沒問題,沒有錯誤,但它不會提示菜單中的選定項目。popup下拉菜單選擇

jsfiddle link

$(document).ready(function() { 
    // this function is triggered as soon as something changes in the form 
    $("select[name='inptPAN']").change(function() { 
     //console.log('found change'); 
     alert($(this).val()); 

}); 
} 

HTML:

<div id='selectPopup'> 
    <form name='test'> 
     <select id='inptPAN' name='inptPAN'> 
      <option value='1'>item 1</option> 
      <option value='2'>item 2</option> 
      <option value='3'>item 3</option> 
      <option value='4'>item 4</option> 
      <option value='5'>item 5</option> 
      <option value='6'>item 6</option> 
     </select> 
    </form> 
</div> 

回答

3

沒有錯誤,但它不會從菜單提示選擇的項目。

沒有小提琴包含錯誤,您可以在控制檯中看到錯誤。

錯誤是:您缺少$(document).ready的結尾。

語法是:

$(document).ready(function() {  
}); 

試試這個:

的document.ready的
$(document).ready(function() {  
    $("select[name='inptPAN']").change(function() { 
      alert($(this).val());   
    }); 
}); 

Working Code

+0

感謝,它是好的,將選擇回答 –

3

你沒有正確地完成了功能

$(document).ready(function() { 
    // this function is triggered as soon as something changes in the form 
    $("select[name='inptPAN']").change(function() { 
     //console.log('found change'); 
     alert($(this).val()); 

}); 
});//you missed it 
1

語法是這裏的問題..

$(document).ready(function() {  
}); 

您必須關閉的document.ready函數的});代替}

你的代碼看起來應該是這樣..

$(document).ready(function() {  
    $("select[name='inptPAN']").change(function() { 
      alert($(this).val());   
    }); 
}); 
1

你的代碼是不完整的。把);放在最後。像下面

$(document).ready(function() { 
    // this function is triggered as soon as something changes in the form 
    $("select[name='inptPAN']").change(function() { 
     //console.log('found change'); 
     alert($(this).val()); 

}); 
}); 
1
$(document).ready(function() { 
// this function is triggered as soon as something changes in the form 
$("select[name='inptPAN']").change(function() { 
    //console.log('found change'); 
    alert($(this).val()); 
    }); 
}); 
+0

請避免添加代碼只有答案,也注入了一些解釋。 – rekaszeru