Javascript 无法访问Java脚本文件夹

Javascript 无法访问Java脚本文件夹,javascript,asp.net,webforms,Javascript,Asp.net,Webforms,基本上,我正在尝试添加我的单选按钮脚本文件,当用户单击另一个按钮时,该脚本文件将删除所有选定的按钮。基本上,它会阻止用户选择1个以上的单选按钮。但是,我不能。以下是我的Java脚本代码: $().ready(function () { var $allAccountSelectionRadios = $('.AccountSelectionRadio > input:radio'); $allAccountSelectionRadios.click(function

基本上,我正在尝试添加我的
单选按钮
脚本文件,当用户单击另一个按钮时,该脚本文件将删除所有选定的按钮。基本上,它会阻止用户选择1个以上的
单选按钮
。但是,我不能。以下是我的Java脚本代码:

    $().ready(function () {
    var $allAccountSelectionRadios = $('.AccountSelectionRadio > input:radio');
    $allAccountSelectionRadios.click(function () {
        $allAccountSelectionRadios.not(this).each(function () {
            this.checked = false;

        });
    });
});
下面是我的asp.net代码:

<head runat="server">
<title>Lab 11 - Exception Handling and Error Logging</title>
<script src="Scripts/jquery-3.0.0.js"></script>
<script src="script/AccountPageScript.js" type="text/javascript"></script>
</head>

<body>
    <form id="form1" runat="server">
        <div id="Div1" runat="server">
            <asp:Panel ID="AccountPanel" runat="server" GroupingText="Account Details" Visible="true">
                <asp:Repeater ID="AccountInfoRepeater" runat="server" Visible="true">
                    <HeaderTemplate>
                            <table>
                            <thead>
                                <asp:TableHeaderCell ColumnSpan="2" runat="server" HorizontalAlign="Left">Account Id</asp:TableHeaderCell>
                                <asp:TableHeaderCell runat="server" HorizontalAlign="Left">Account Type</asp:TableHeaderCell>
                                <asp:TableHeaderCell runat="server" HorizontalAlign="Left">Balance</asp:TableHeaderCell>
                                <asp:TableHeaderCell runat="server" HorizontalAlign="Left">Currency</asp:TableHeaderCell>
                            </thead>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <tr>
                            <td>
                                <asp:RadioButton ID="AccountSelectionRadioButton" runat="server" />
                            </td>
                            <td>
                                <asp:Label ID="AccountIDLabel" runat="server" Text='<%# Eval("Id") %>' />
                            </td>
                            <td>
                                <asp:Label ID="AccountTypeLabel" runat="server" Text='<%# Eval("Type") %>' />
                            </td>
                            <td>
                                <asp:Label ID="AmountLabel" runat="server" Text='<%# Eval("Amount") %>' />
                            </td>
                            <td>
                                <asp:Label ID="CurrencyLabel" runat="server" Text='<%# Eval("Currency") %>' />
                            </td>
                        </tr>
                    </ItemTemplate>
                    <FooterTemplate>
                        </table>
                    </FooterTemplate>
                </asp:Repeater>
                <div></div>
                <asp:Label ID="EnterAmountLabel" runat="server" Text="Enter Amount: " />
                <asp:TextBox ID="WithdrawalAmountTextBox" runat="server" />
                <asp:Button ID="SubmitButton" runat="server" Text="Submit" />
                <div></div>
                <asp:CustomValidator ID="CustomValidator" runat="server" ErrorMessage="You have to select at least one account " OnServerValidate="ValidateAccountIdSelection" Display="None" />
                <asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server" ErrorMessage="You have to enter a double value" ControlToValidate="WithdrawalAmountTextBox" Display="None" />
                <asp:CompareValidator ID="CompareValidator" runat="server" ErrorMessage="You have to enter a double value " ControlToValidate="WithdrawalAmountTextBox" Type="Double" Operator="DataTypeCheck" Display="None" />
                <div></div>
                <asp:ValidationSummary ID="ValidationSummary" runat="server" />
            </asp:Panel>
            <asp:Panel ID="ErrorPanel" runat="server" Visible="false">
                <asp:Label ID="SimpleBankErrorMessage" runat="server" />
            </asp:Panel>
        </div>
    </form>
</body> 

实验11-异常处理和错误记录
帐户Id
帐户类型
平衡
通货
您是否知道是什么导致了这个问题,或者您是否有任何链接来回答这个问题

谢谢大家,祝你们今天愉快

编辑:

以下是用HTML生成的代码:

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<script src="/WebResource.axd?d=pynGkmcFUV13He1Qd6_TZDo7pde1PlC3CEuIL05u8Q1xzcqV3PrxQf6BV-yOWDawu00wwYzaAVDc3H21VtA9QA2&amp;t=635588690558757176" type="text/javascript">    </script>


<script src="/WebResource.axd?d=x2nkrMJGXkMELz33nwnakICvsGmK5SdM9dk67DGoGLRbDkaJ4AV4SDiDiYXmeJzOvX1FlDmSjt4uSO7vYhQSbfgakaHhNd17j5pdlKG7J5s1&amp;t=635588690558757176" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
    }
//]]>
</script>

//
//

为什么不在服务器端执行此操作???用c#。 您所有的单选按钮都是runat=“server”,因此您也可以让事件侦听器通过它们并进行检查

$().ready(function () {
var $allAccountSelectionRadios = $('.AccountSelectionRadio > input:radio');
$allAccountSelectionRadios.click(function () {
    $allAccountSelectionRadios.not(this).each(function () {
        this.attr('checked',false);
    });
});
this.attr('checked',false);这就是我做这件事的方式。
但是我不记得它是否能与ASP.Net事件侦听器一起工作。

为什么不在服务器端执行此操作???用c#。 您所有的单选按钮都是runat=“server”,因此您也可以让事件侦听器通过它们并进行检查

$().ready(function () {
var $allAccountSelectionRadios = $('.AccountSelectionRadio > input:radio');
$allAccountSelectionRadios.click(function () {
    $allAccountSelectionRadios.not(this).each(function () {
        this.attr('checked',false);
    });
});
this.attr('checked',false);这就是我做这件事的方式。
但是我记不起它是否可以与ASP.Net事件侦听器一起使用。

您需要使单选按钮相互排斥。一种方法是将所有单选按钮的
名称属性设置为相同的值。要实现此目的,请将脚本替换为:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $('input:radio').each(function () {
            $(this).attr('name', 'AccountSelectionRadioButtons')
        });
    });
</script>

$(函数(){
$('input:radio')。每个(函数(){
$(this.attr('name','AccountSelectionRadioButtons'))
});
});

您需要使单选按钮相互排斥。一种方法是将所有单选按钮的
名称
属性设置为相同的值。要实现此目的,请使用以下内容替换脚本:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $('input:radio').each(function () {
            $(this).attr('name', 'AccountSelectionRadioButtons')
        });
    });
</script>

$(函数(){
$('input:radio')。每个(函数(){
$(this.attr('name','AccountSelectionRadioButtons'))
});
});

我用你的代码更改了我的代码,但没有用。我很确定代码是正确的(它在家庭作业中给出)。是的,也许你是对的,但这是家庭作业,所以我们需要这样做。你能分享生成的HTML吗:)然后我可以看一下:)我想原始HTML:)带有HTML表单和单选按钮:啊。整个页面,就像您在浏览器中看到它一样。只需将其粘贴到pastebin或类似的东西中,并共享链接。我用您的代码更改了我的代码,但没有任何帮助。我很确定代码是正确的(它在家庭作业中给出)。是的,也许你是对的,但这是家庭作业,所以我们需要这样做。你能分享生成的HTML吗:)然后我可以看一下:)我想原始HTML:)带有HTML表单和单选按钮:啊。整个页面,就像您在浏览器中看到它一样。只需将其粘贴到pastebin或类似的东西中并共享链接。感谢它的工作,但这一次,当我按下我的提交按钮时,我的
验证程序会说“你必须至少选择一个帐户。”。我的意思是当我一个接一个地选择一个
单选按钮
时,它会在视觉上工作并显示只选择了一个
单选按钮
。但是,这次没有一个被选中。实际上我的验证器逻辑肯定是这样的。我正在逐个检查每个
单选按钮
,然后如果其中一个被选中,那么
是否有效
=true。感谢它的工作,但这次,当我按下提交按钮时,我的
验证程序
会说“您必须选择至少一个帐户。”。我的意思是当我一个接一个地选择一个
单选按钮
时,它会在视觉上工作并显示只选择了一个
单选按钮
。但是,这次没有一个被选中。实际上我的验证器逻辑肯定是这样的。我正在逐个检查每个
单选按钮
,如果其中一个按钮被选中,则
是否有效
=true。