繁体   English   中英

根据 div 中的文本禁用提交按钮

[英]Disable the submit button based on text inside div

所以我有这个功能,如果选择了第二个选项,则禁用提交按钮。

        $(document).ready(function () {
            $('#estadoTicketSel').change(function () {
                if ($(this).find('option:selected').text() == 'Fechado') {
                    $('#submitButton').prop('disabled', true);
                    $('#notificaFechado').show();
                } else {
                    $('#submitButton').prop('disabled', false);
                    $('#notificaFechado').hide();
                }
            });
        });

但是,我正在尝试根据 div 内的文本禁用该按钮。 我试过这个没有成功...

        $(document).ready(function () {
            $(function(){
                var txt = $('#state p').text();
                    if(txt == 'Fechado'){
                        $('#submitButton').prop('disabled', true);
                        $('#notificaFechado').show();
                }
         });
      });

 <div id="state"><p>@estadoTicket</p></div>

有什么想法吗 ?

更新:

摆弄选择框: http : //jsfiddle.net/q2VRH/
从 div 中读取小提琴: http : //jsfiddle.net/f3nzk/

因此,正如您所看到的,小提琴正在工作,我发现问题在于我的数据库中的值是什么。 传递的值是这样的:

费查多。

感谢大家的帮助。

我会把小提琴留在这里,给需要的人。 再次感谢。

尝试修剪文本:

var txt = $.trim($('#state p').text());

文件

您是否尝试过使用indexOf

if(txt.indexOf('Fechado') > -1){
   //do stuff
}

如果搜索值从未出现,则索引将为 -1。

这是小提琴http://jsfiddle.net/symonsarwar/q2VRH/1/

 $(document).ready(function () {
                $('#estadoTicketSel').change(function () {
                    if ($(this).find('option:selected').text() == 'Fechado') {
                        $('#submitButton').attr('disabled', true);
                        $('#notificaFechado').show();
                    } else {
                        $('#submitButton').prop('disabled', false);
                        $('#notificaFechado').hide();
                    }
                });
            });

暂无
暂无

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

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