为什么这个jQuery会导致我的jQuery全部失败?

克莱·香农(B. Clay Shannon)

我添加了此jQuery,以尝试有条件地显示某些元素:

$(document).on("click", '[id$=btnAddFoapalRow]', function (e) {
    if $('[id$=foapalrow3]').not(":visible");
        $('[id$=foapalrow3]').slideDown();
    } 
    else if $('[id$=foapalrow4]').not(":visible");
        $('[id$=foapalrow4]').slideDown();
    }
});

该代码基于此处的代码我将“是”更改为“不是”,因为当行可见时我需要采取行动

...但它不仅不起作用(单击“ +”按钮(btnAddFoapalRow)无法使行可见),还导致其前面的其他jQuery也无法正常工作。上面的jQuery有什么问题,为什么它如此令人讨厌/妨碍他人?

这是所有上下文/您的阅读乐趣的jQuery:

$(document).ready(function () {
    console.log('The ready function has been reached'); /* This is a "sanity check" so it can be verified that this jQuery script is running/ran */
});

/* If the select "Yes" (self-identify as UCSC Faculty, Staff, or Student), prompt them to log in */
$(document).on("change", '[id$=ckbxUCSCFacultyStaffOrStudent]', function () {
    var ckd = this.checked;
    if (ckd) alert('Please log in prior to continuing with this form');
});

/* If the select "Yes" (they are seeking payment for themselves, as opposed to someone else), omit (invisibilize) sections 2 and 3 on the form */
$(document).on("change", '[id$=ckbxPaymentForSelf]', function () {
    if (this.checked) {
        $('[id$=panelSection2]').slideUp();
        $('[id$=panelSection3]').slideUp();
        $('[id$=rbPaymentToIndividual]').prop("checked", true);
        $('[id$=_MailStopRow]').slideDown();
        $('[id$=_AddressRows]').slideUp();
    }
    else {
        $('[id$=panelSection2]').slideDown();
        $('[id$=panelSection3]').slideDown();
        $('[id$=rbPaymentToIndividual]').prop("checked", false);
        $('[id$=_MailStopRow]').slideUp();
        $('[id$=_AddressRows]').slideDown();
    }
});

/* When "UCSC insider" checkbox changes state, set up txtbxSSNOrITIN accordingly - was ckbxEmp, which has been deprecated/removed */
$(document).on("change", '[id$=ckbxUCSCFacultyStaffOrStudent]', function () {
    var ssnmaxlen = 4;
    var itinmaxlen = 11;
    var ssntextboxwidth = 40;
    var itintextboxwidth = 100;
    var ckd = this.checked;
    var $input = $('[id$=txtbxSSNOrITIN]');
    var $lbl = $('[id$=lblSSNOrITIN]');

    if (ckd) $input.data("oldValue", $input.val()); // Remember current value

    $input.prop("maxlength", ckd ? ssnmaxlen : itinmaxlen).css({
        background: ckd ? 'yellow' : 'lightgreen',
        width: ckd ? ssntextboxwidth : itintextboxwidth
    }).val(function (i, v) {
        /* If checked, trim textbox contents to ssnmaxlen characters */
        return ckd && v.length > ssnmaxlen ? v.slice(0, ssnmaxlen) : $input.data("oldValue");
    });

    $lbl.text(ckd ? "SSN - last 4 digits" : "ITIN");
    /* This sets focus to the end of the textbox (multiplication by 2 is because some characters are counted as two) */
    var strLength = $input.val().length * 2;
    $input.focus();
    $input[0].setSelectionRange(strLength, strLength);
});

$(document).on("keypress", '[id$=txtbxSSNOrITIN]', function (e) { 
    /* For now, just "eating" non-numeric entries (from http://jsfiddle.net/zpg8k/); will change when the business rules for ITIN are known */
    var k = e.which;
    if (k < 48 || k > 57) { e.preventDefault(); }
});

$(document).on("click", '[id$=btnAddFoapalRow]', function (e) {
    if $('[id$=foapalrow3]').not(":visible");
        $('[id$=foapalrow3]').slideDown();
    } 
    else if $('[id$=foapalrow4]').not(":visible");
        $('[id$=foapalrow4]').slideDown();
    }
});

这是在SharePoint 2010项目中。我也尝试使用服务器端(C#)代码来完成相同的操作,但是由于每次单击按钮再次提交页面,该操作也不起作用。我在这里问了一下[为什么我的不提交(HtmlButton)仍然提交?

后面的相关代码是:

HtmlButton btnAddFoapalRow = null;
. . .       
btnAddFoapalRow = new HtmlButton();
btnAddFoapalRow.Attributes["type"] = "button";
btnAddFoapalRow.InnerHtml = "+"; 
btnAddFoapalRow.ID = "btnAddFoapalRow";
this.Controls.Add(btnAddFoapalRow);    


foapalrow3 = new HtmlTableRow();
foapalrow3.ID = "foapalrow3";
foapalrow3.Visible = false;
. . .
foapalrow3 = new HtmlTableRow();
foapalrow3.ID = "foapalrow3";
foapalrow3.Visible = false;

更新

我将jQuery更改为此,以便可以验证是否已到达代码(将调用添加到console.log()):

$(document).on("click", '[id$=btnAddFoapalRow]', function (e) {
    if ($('[id$=foapalrow3]').not(":visible")) {
        console.log('reached the foapalrow3 not visible branch');
        $('[id$=foapalrow3]').slideDown();
    }
    else if ($('[id$=foapalrow4]').not(":visible")) {
        console.log('reached the foapalrow4 not visible branch');
        $('[id$=foapalrow4]').slideDown();
    }
});

...而且我确实在Chrome的控制台中看到“已到达foapalrow3不可见的分支”,但页面上的外观没有任何变化。

我想知道我是否真的需要这样的东西:

$('[id$=foapalrow3]').visible();

而不是这样:

$('[id$=foapalrow3]').slideDown();

如果是这样,正确的语法是什么(将visible设置为true)?

更新2

我尝试了这个:

$('[id$=foapalrow3]').attr("visibility", "visible");

...但是在Mudville没有喜悦。

Praveen Kumar Purushothaman

这是完全错误的:

if $('[id$=foapalrow3]').not(":visible");
    $('[id$=foapalrow3]').slideDown();
} 
else if $('[id$=foapalrow4]').not(":visible");
    $('[id$=foapalrow4]').slideDown();
}

更改为:

if ($('[id$=foapalrow3]').not(":visible")) {
    $('[id$=foapalrow3]').slideDown();
} 
else if ($('[id$=foapalrow4]').not(":visible")) {
    $('[id$=foapalrow4]').slideDown();
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么空200会导致jQuery失败?

来自分类Dev

为什么这个简单的getInteger函数会导致流失败?

来自分类Dev

为什么rsync会导致我的系统启动失败?

来自分类Dev

为什么这个条件会导致错误?

来自分类Dev

为什么添加jQuery Mobile会导致HTML消失?

来自分类Dev

为什么这个 angularjs ui-router 代码会导致我的浏览器崩溃?

来自分类Dev

为什么添加这个构造函数会导致我的 API 在 C# 中工作?

来自分类Dev

为什么这个茉莉花间谍会导致错误?

来自分类Dev

为什么这个while循环会导致无限循环?

来自分类Dev

为什么这个while循环会导致无限循环?

来自分类Dev

为什么这个双变量会导致分段错误?

来自分类Dev

为什么此优化会导致我的合并排序失败?

来自分类Dev

为什么这个 ROUTE ADD 命令会失败?

来自分类Dev

Java 泛型:为什么这个嵌套模板会失败?

来自分类Dev

为什么在textFile上映射会导致编译失败?

来自分类Dev

为什么postharp会导致Web项目在发布时失败?

来自分类Dev

为什么Apache会导致DNS查找失败?

来自分类Dev

为什么对SO的setgid权限会导致失败?

来自分类Dev

为什么 enable_if 失败会导致编译时错误?

来自分类Dev

为什么这个jQuery颜色选择器在Bootstrap模式下失败?

来自分类Dev

为什么这个jQuery颜色选择器在Bootstrap模式下失败?

来自分类Dev

为什么这个jQuery不起作用?

来自分类Dev

为什么这个jQuery不起作用?

来自分类Dev

为什么这个Jquery / JavasScript这么慢?

来自分类Dev

你知道我为什么会遇到这个问题吗

来自分类Dev

为什么这个函数会破坏我数组中的值?

来自分类Dev

为什么serviceworker会导致第二个jquery帖子立即停滞?

来自分类Dev

为什么会失败?

来自分类Dev

为什么这个 jQuery 代码比这个慢得多?

Related 相关文章

  1. 1

    为什么空200会导致jQuery失败?

  2. 2

    为什么这个简单的getInteger函数会导致流失败?

  3. 3

    为什么rsync会导致我的系统启动失败?

  4. 4

    为什么这个条件会导致错误?

  5. 5

    为什么添加jQuery Mobile会导致HTML消失?

  6. 6

    为什么这个 angularjs ui-router 代码会导致我的浏览器崩溃?

  7. 7

    为什么添加这个构造函数会导致我的 API 在 C# 中工作?

  8. 8

    为什么这个茉莉花间谍会导致错误?

  9. 9

    为什么这个while循环会导致无限循环?

  10. 10

    为什么这个while循环会导致无限循环?

  11. 11

    为什么这个双变量会导致分段错误?

  12. 12

    为什么此优化会导致我的合并排序失败?

  13. 13

    为什么这个 ROUTE ADD 命令会失败?

  14. 14

    Java 泛型:为什么这个嵌套模板会失败?

  15. 15

    为什么在textFile上映射会导致编译失败?

  16. 16

    为什么postharp会导致Web项目在发布时失败?

  17. 17

    为什么Apache会导致DNS查找失败?

  18. 18

    为什么对SO的setgid权限会导致失败?

  19. 19

    为什么 enable_if 失败会导致编译时错误?

  20. 20

    为什么这个jQuery颜色选择器在Bootstrap模式下失败?

  21. 21

    为什么这个jQuery颜色选择器在Bootstrap模式下失败?

  22. 22

    为什么这个jQuery不起作用?

  23. 23

    为什么这个jQuery不起作用?

  24. 24

    为什么这个Jquery / JavasScript这么慢?

  25. 25

    你知道我为什么会遇到这个问题吗

  26. 26

    为什么这个函数会破坏我数组中的值?

  27. 27

    为什么serviceworker会导致第二个jquery帖子立即停滞?

  28. 28

    为什么会失败?

  29. 29

    为什么这个 jQuery 代码比这个慢得多?

热门标签

归档