简体   繁体   English

弹出下拉菜单选择

[英]popup dropdown item selection

Here is my dropdown menu. 这是我的下拉菜单。 code seems ok, no error but it does not alert selected item from menu. 代码似乎还可以,没有错误,但是不会警告菜单中的选定项目。

jsfiddle link jsfiddle链接

$(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: 的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>

You are not rightly finished the function 您未正确完成功能

$(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

no error but it does not alert selected item from menu. 没有错误,但不会警告菜单中的选定项目。

No the fiddle contains the error, you can see the error in console. 没有小提琴包含错误,您可以在控制台中看到该错误。

Error is : you are missing end of $(document).ready . 错误是:您缺少$(document).ready结尾。

Syntax is: 语法是:

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

Try this : 尝试这个 :

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

Working Code 工作守则

Syntax of document.ready is the problem here.. 问题是document.ready的语法。

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

You must close the document.ready function with }); 您必须使用});关闭document.ready函数}); instead of } 代替}

Your code should look like this.. 您的代码应如下所示。

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

Your code is incomplete. 您的代码不完整。 Put ); ); at the end. 在末尾。 like the following 像下面

$(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());

});
});
$(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());
  });
});

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

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