Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript单选按钮不适用于IE7和IE8_Javascript_Html_Forms_Internet Explorer 8_Internet Explorer 7 - Fatal编程技术网

javascript单选按钮不适用于IE7和IE8

javascript单选按钮不适用于IE7和IE8,javascript,html,forms,internet-explorer-8,internet-explorer-7,Javascript,Html,Forms,Internet Explorer 8,Internet Explorer 7,我想使用单选按钮选择要在表单上提交的字段。 我正在使用以下脚本: <script> function validateForm(){ var x=document.forms["preinsert"]["RIF"].value; var y=document.forms["preinsert"]["CTP"].value; var xd=document.forms["preinsert"]["RIF"].disabled;

我想使用单选按钮选择要在表单上提交的字段。 我正在使用以下脚本:

<script>
    function validateForm(){
        var x=document.forms["preinsert"]["RIF"].value;
        var y=document.forms["preinsert"]["CTP"].value;
        var xd=document.forms["preinsert"]["RIF"].disabled;
        var yd=document.forms["preinsert"]["CTP"].disabled;
        if (xd == false){
            if (x==null || x==""){
                alert("The first field can't be empty.");
                return false;
            }
        }
        else if (yd == false){
            if (y==null || y==""){
                alert("The second field can't be empty.");
                return false;
            }
        }
    }
</script>

函数validateForm(){
var x=文件.forms[“preinsert”][“RIF”].值;
变量y=文件.forms[“preinsert”][“CTP”]。值;
var xd=document.forms[“preinsert”][“RIF”]。已禁用;
var yd=文件。表格[“预插入”][“CTP”]。已禁用;
如果(xd==false){
如果(x==null | | x==“”){
警报(“第一个字段不能为空。”);
返回false;
}
}
否则,如果(yd==false){
如果(y==null | | y==“”){
警报(“第二个字段不能为空。”);
返回false;
}
}
}
关于此HTML代码:

<form name="preinsert" action="/ServletPreInsert" method="post" onsubmit="return validateForm()">
    <table>
        <tr>
            <td>
                <input type="radio" name="rad" checked="checked" onclick="RIF.disabled=false; CTP.disabled=true;"/>
                <select name="RIF1" class="right-select">
                    <option selected="selected">NB</option>
                    <option>LTI</option>
                </select>
            </td>
            <td>
                <input id="RIF" name="RIF" class="fixed-input" type="text">
            </td>
        </tr>
        <tr>
            <td>
                <input type="radio" name="rad" onclick="RIF.disabled=true; CTP.disabled=false;"/>Counterparty
            </td>
            <td>
                <select id="CTP" name="CTP" class="fixed-select" disabled>
                    <option>Option_1</option>
                    <option>Option_2</option>
                    <option>Option_3</option>
                </select>
            </td>
        </tr>
    </table>
    </br></br>
    <p align="right"><input type="submit" value="Insert"></p>
</form>

铌
LTI
交易对手
方案1
方案2
方案3


我注意到的是:如果我在IE7/8之类的浏览器上使用此代码,当我选择第二个单选按钮(一个选项)然后提交表单时,javascript会显示错误消息:“第二个字段不能为空。” 但是,如果我在第一个字段中键入某个内容,并且选中了第一个单选按钮,则它可以按照我的需要工作

这种“疯狂”的事情不会发生在Firefox26.0上


那么,出什么问题了?

如果您想让它在IE7/8上工作,您必须更改它:

<select id="CTP" name="CTP" class="fixed-select" disabled>
    <option>Option_1</option>
    <option>Option_2</option>
    <option>Option_3</option>
</select>

方案1
方案2
方案3
为此:

<select id="CTP" name="CTP" class="fixed-select" disabled>
    <option value="Option_1">Option_1</option>
    <option value="Option_2">Option_2</option>
    <option value="Option_3">Option_3</option>
</select>

方案1
方案2
方案3

因为如果未设置
value
参数,它将始终显示为
null
值。

说真的,您正在使用窗口上的全局名称访问元素,并将其设置为禁用onclick等。我觉得这一切都很可疑。您有何建议?谢谢。我建议使用合适的事件处理程序和选择器。如果有效,我同意你的建议。你能举个例子来回答吗?我对你给我的建议不太“自信”。