jquery验证只是不会生活元素

时间:2011-08-30 10:39:02

标签: jquery jquery-validate

我一直试图在点击按钮时使用JavaScript生成的元素上添加条件验证。

我正在添加一个新的评论员下拉列表&单击一个名为“添加新评论”的按钮评论文本区域,该按钮完美无缺。

如果从下拉列表中选择了评论员,我希望jquery验证验证评论字段是必须的。请参阅下面的代码

$('#addcomment').live('click', function()
{
    epc_last_element= $("[id^=commentor]").filter(':last').attr('id');
    epc_no= parseInt(epc_last_element.replace(/commentor/, '')) + 1;

    $('#tr_addcomment').before(comment_html.replace(/\[###epc_no###\]/g, epc_no));

    $('#commentor' + epc_no + ' option:first').attr('selected','selected');
    tinyMCE.execCommand('mceAddControl', false, 'comment' + epc_no);


    $('#comment' + epc_no).rules("add", {
                                required: function(element) {
                                 return $('#commentor' + epc_no).val() != '';
                                }
    });
});

上面的代码不起作用,但如果我只设置“required:true”而不是条件,那么这将完美地运作。

会对这个棘手的人提供一些帮助。

此致 PRATIK

0 个答案:

没有答案