Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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 文本框切换JQuery_Javascript_Jquery - Fatal编程技术网

Javascript 文本框切换JQuery

Javascript 文本框切换JQuery,javascript,jquery,Javascript,Jquery,我有以下代码,其中文本框的启用和禁用不起作用: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>TEST</title> <!-- JQuery 1.12.3 JS --&

我有以下代码,其中文本框的启用和禁用不起作用:

    <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TEST</title>
<!-- JQuery 1.12.3 JS -->
    <script src="../js/jquery-1.12.3.min.js"></script>
</head>
<body>
    <table>
        <tr>
            <td><label class="control-label">Mode</label></td>
            <td>&nbsp;
                <label><input type="radio" name="payMode" value="cash" checked>Cash</label>
                <label><input type="radio" name="payMode" value="cheque">Cheque</label>
            </td>
        </tr>
        <tr>
            <td><label>Cheque No</label></td>
            <td><input type="number" name="chequeNo" pattern="^[0-9]" min="0" step="1" class="form-control" placeholder="Enter Cheque No" disabled></td>
        </tr>
        <tr>
            <td><label>Cheque Date</label></td>
            <td><input type="date" name="chequeDate" class="form-control" placeholder="Enter Cheque Date" disabled></td>
        </tr>
    </table>
<script>
 <script>
        $(':radio[name=payMode]').change(function () {
    var prop = this.value == 'cash';
    $('input[name=chequeNo], input[name=chequeDate]').prop({ disabled: prop, required: !prop });
});
</script>
</body>
</html>

试验
模式
现金
支票
支票号码
支票日期
$(':radio[name=payMode]')。更改(函数(){
var prop=this.value==“现金”;
$('input[name=chequeNo],input[name=chequeDate]').prop({禁用:prop,必需:!prop});
});

基本上,我正在尝试根据收音机的点击启用两个文本框。如果用户选择付款模式为支票,则启用支票编号和支票日期文本框。如果用户选择现金,则禁用2个文本框。请注意

您有两个起始脚本标记,内部脚本标记将导致javascript错误

编辑

这里是JSFIDLE的链接,证明了这一点,我只删除了重复的标记。有时简单的答案是最好的:)


$(':radio[name=payMode]')。更改(函数(){
var prop=this.value==“现金”;
$('input[name=chequeNo],input[name=chequeDate]').prop({禁用:prop,必需:!prop});
});

下面的示例显示了当用户更改“支付模式”单选按钮时,如果用户选择支付模式为支票,则启用支票编号和支票日期文本框。如果用户选择现金,则禁用并清空2个文本框

$(“输入[name=payMode]”)。在(“更改”,函数()上{
如果($(this.val()=“支票”){
$(“input[name=chequeNo],input[name=chequeDate]”)attr(“disabled”,false);
}否则{
$(“输入[name=chequeNo],输入[name=chequeDate]”).val(“”.attr(“禁用”,true);
}
});

试验
模式
现金
支票
支票号码
支票日期

这根本不能回答问题。这应该是一个注释,因为内部脚本标记会导致javascript错误,所以是的,它确实回答了这个问题。我怎么能确定呢,我只知道这是个问题,如果这不能解决它,他可以回复,我会帮助他more@Zach您是正确的,它将无法使用额外的
标记。请用演示作为证明,先生。@zer00ne,不幸的是,我在手机上,但我会尝试制作一个here@Zach剪切并粘贴问题代码,确保jQuery的标记是绝对路径。如果可以的话,请注释掉额外的标记。工作很好。你犯了什么错误?@guratio你是对的,代码运行正常。我有重复的脚本标记,因此出现了问题。
<script>
        $(':radio[name=payMode]').change(function () {
    var prop = this.value == 'cash';
    $('input[name=chequeNo], input[name=chequeDate]').prop({ disabled: prop, required: !prop });
});
</script>