简体   繁体   English

在SharePoint 2010中使用jQuery有条件地隐藏内容

[英]Hiding content conditionally using jQuery in SharePoint 2010

I am developing a Blog for SharePoint 2010. I already have everything set up, but now I need to install a Capcha for validation before a user can comment on a post. 我正在为SharePoint 2010开发博客。已经设置了所有内容,但是现在我需要安装Capcha进行验证,然后用户才能对帖子发表评论。 I have a web part developed for the capcha. 我有一个为验证码开发的Web部件。 I was thinking that I could use the text value of the span id"ctl00_m_g_c9d562b9_1531_47ac_b0f0_24f06ecea4cc_MessageLabel" (You've got to love sharepoint naming lol) and jQuery to show and hide the comments portion based on if there is a value of success!. 我当时以为我可以使用跨度ID“ ctl00_m_g_c9d562b9_1531_47ac_b0f0_24f06ecea4cc_MessageLabel”(您一定喜欢共享点命名,哈哈)和jQuery的文本值来显示和隐藏基于成功值的注释部分! Unfortunately, I am having little success getting this to work. 不幸的是,要使它正常工作,我收效甚微。 Here is my code... 这是我的代码...

<script type="text/javascript">
    $(document).ready(function(){
     $("#WebPartWPQ7").hide();
     if($("#ctl00_m_g_c9d562b9_1531_47ac_b0f0_24f06ecea4cc_MessageLabel").text() == success!) {
      $("#WebPartWPQ7").show();
     };
    });
</script>

I am a nube to coding and could use any guidance or suggestions. 我是编码的专家,可以使用任何指导或建议。

Thank you! 谢谢!

<script type="text/javascript">
    $(document).ready(function(){
        var webPart = $("#WebPartWPQ7").hide();
        if($("#ctl00_m_g_c9d562b9_1531_47ac_b0f0_24f06ecea4cc_MessageLabel").text() == "success!") {
            webPart.show();
        };
    });
</script>

Your "success" it's a variable? 您的“成功”是变量吗? Maybe you just missed the quotes. 也许您只是错过了引号。

 if($("#ctl00_m_g_c9d562b9_1531_47ac_b0f0_24f06ecea4cc_MessageLabel").text() == "success!") {

You missed the double quotes on success! 您错过了success!的双引号success! . You also need to attach this to some kind of event, or jQuery will evaluate this code once on document ready and never again. 您还需要将其附加到某种事件上,否则jQuery将在文档准备就绪后立即评估此代码,而不再进行评估。 Perhaps like this? 也许是这样?

$(document).ready(function(){
 $("#WebPartWPQ7").hide();
 $("#captcha_input").change(function(){
   if($("#ctl00_m_g_c9d562b9_1531_47ac_b0f0_24f06ecea4cc_MessageLabel").text() == success!) {
    $("#WebPartWPQ7").show();
 });
 };
});

This checks for success every time you change the capcha input. 每次更改验证码输入时,这都会检查是否成功。

Rather than hiding your "WebPartWPQ7" element on the document ready, just give it the css style display:none (this will hide the element by default) 与其在文档上隐藏“ WebPartWPQ7”元素,不如将其设置为css样式display:none (默认情况下将隐藏该元素)

Also, you need to have quotes around your success! 此外,您还需要引用成功的名言!

<script type="text/javascript">
    $(document).ready(function()
    {
            if($("#ctl00_m_g_c9d562b9_1531_47ac_b0f0_24f06ecea4cc_MessageLabel").text() == "success!")
            {
                    $("#WebPartWPQ7").show();
            };
    });
</script>

Have you tried putting "success!" 您是否尝试过放置“成功!” in quotes? 引号?

Usually with Recaptcha you will allow the user to type the comment, fill in the Recaptcha, and then click "Enter" or "Ok". 通常,使用Recaptcha,您将允许用户键入注释,填写Recaptcha,然后单击“ Enter”或“ Ok”。 Then the server would check the Recaptcha and either allow the comment or deny it. 然后,服务器将检查Recaptcha并允许评论或拒绝评论。 I don't really understand what you're trying to do. 我不太了解您要做什么。

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

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