如果条件为false,则使用jquery阻止SharePoint 2010中的默认列表新表单

时间:2013-07-04 05:28:00

标签: javascript jquery sharepoint sharepoint-2010

The SharePoint 2010 List new form has 10 checkboxes. I want to select only 3 (also not less than) of them.
I used jquery for this but when condition is false then form does not stop doing submit action.

HTML:

<TD><SPAN class=ms-RadioText title=One>
<INPUT id=ctl00_m_g_69fc6715_3136_4421_a83a_06892e860a7a_ff21_ctl00_ctl00 type=checkbox name=ctl00$m$g_69fc6715_3136_4421_a83a_06892e860a7a$ff21$ctl00$ctl00></SPAN></TD>

同样有10个TD元素。

保存按钮:

<INPUT accessKey=O id=ctl00_m_g_69fc6715_3136_4421_a83a_06892e860a7a_savebutton2_ctl00_diidIOSaveItem class=ms-ButtonHeightWidth onclick='if (!PreSaveItem()) return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$m$g_69fc6715_3136_4421_a83a_06892e860a7a$savebutton2$ctl00$diidIOSaveItem", "", true, "", "", false, true))' value=Save type=button name=ctl00$m$g_69fc6715_3136_4421_a83a_06892e860a7a$savebutton2$ctl00$diidIOSaveItem target="_self" jQuery1372914969010="1">

jquery: 

$("#ctl00_m_g_69fc6715_3136_4421_a83a_06892e860a7a_savebutton2_ctl00_diidIOSaveItem").click(function() {

    if($('.ms-RadioText input:checked').length!=3) // ms-RadioText is a class
       {
           alert("You have to select any 3 options");
            e.preventDefault();
            e.returnvalue=false // for IE only
            return false; 
       }
});

我使用了所有三个选项(也是一个一个)来阻止提交操作但没有结果。

1 个答案:

答案 0 :(得分:0)

你必须在函数中传递事件,否则你的变量e将是未定义的

$("#ctl00_m_g_69fc6715_3136_4421_a83a_06892e860a7a_savebutton2_ctl00_diidIOSaveItem").click(function(e) {

    if($('.ms-RadioText input:checked').length!=3)
       {
           alert("You have to select any 3 options");
            e.preventDefault();
            e.returnvalue=false // for IE only
            return false; 
       }
});

<强> jsfiddle demo

如果不起作用,请检查您的html代码并在属性值周围添加双引号,例如attrib="value"以确保语法正确

我得问,长身份是什么?