0
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; 
       }
});

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

4

1 回答 1

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 演示

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

我要问,长 id 是什么?

于 2013-07-04T05:31:27.450 回答