Javascript不起作用,我不知道为什么

用户名

我从jsfiddle分叉了一些代码,当我将其放入html文档时,它无法正常工作。但是在小提琴中效果很好。某件事告诉我,我缺少一个库,但不确定应该使用哪个库。

如果它实际上在工作,应该发生的是一个文本框,如果选择了另一个单选按钮,则应禁用然后再启用两个。

小提琴可以在这里找到:http : //jsfiddle.net/t5xKW/3/

任何帮助,将不胜感激。

<html>
<head>
<title> text conversion</title>
<script language="JavaScript">
var rbProject = document.getElementById('radio1-1');
var rbAccount = document.getElementById('radio1-2');
var txtRef = document.getElementById('txtRef');
var txtTitle = document.getElementById('txtTitle');
var txtName = document.getElementById('txtName');


rbProject.addEventListener('change', function (e) {
    txtRef.disabled = false;
    txtTitle.disabled = false;
    txtName.disabled = true;
})

rbAccount.addEventListener('change', function (e) {
    txtRef.disabled = true;
    txtTitle.disabled = true;
    txtName.disabled = false;
})
</script>
<style>
#container {
    width:700px;
    border-style:solid;
    border-width:2px;
}
.table {
    display:table;
    width: 650px;
    border-style:solid;
    border-width:1px;
}
.tr {
    display:table-row;
    height:28px;
}
.td {
    display:table-cell;
}
.td1 {
    width:200px;
}
.td2 {
    width:130px;
}
.td3 {
    width:400px;
}
</style>
</head>

<body>
<div class="table">
    <div class="tr">
        <div class="td td1">
            <input type="radio" name="section1a" id="radio1-1" value="radio" />
            <label class="large black" for="radio1-1">Project</label>
        </div>
        <div class="td td2"> <span class="large black">Ref:</span> 
        </div>
        <div class="td td3">
            <input id="txtRef" class="form-textbox" name="ref" type="text" placeholder="Insert project reference" />
        </div>
    </div>
    <div class="tr">
        <div class="td td1"></div>
        <div class="td td2"> <span class="large black">Title:</span> 
        </div>
        <div class="td td3">
            <input id="txtTitle" class="form-textbox" name="title" type="text" placeholder="Insert project title" />
        </div>
    </div>
    <div class="tr">
        <div class="td td1">
            <input type="radio" name="section1a" id="radio1-2" value="radio" />
            <label class="large black" for="radio1-2">Account</label>
        </div>
        <div class="td td2"> <span class="large black">Name:</span> 
        </div>
        <div class="td td3">
            <input id="txtName" class="form-textbox" name="name" type="text" placeholder="Insert account name" />
        </div>
    </div>
    <div class="tr">
        <div class="td td1">
            <input type="radio" name="section1a" id="radio1-3" value="radio" />
            <label class="large black" for="radio1-3">General Business</label>
        </div>
        <div class="td td2"></div>
        <div class="td td3">
            <input class="form-textbox" name="organization" type="text" placeholder="Insert client organisation name" />
        </div>
    </div>
</div>
</body>


</html>
发送

在执行javascript之前未呈现HTML。将您的脚本放在关闭body标签(</body>)之前:

<html>
<head>
<title> text conversion</title>

<style>
#container {
    width:700px;
    border-style:solid;
    border-width:2px;
}
.table {
    display:table;
    width: 650px;
    border-style:solid;
    border-width:1px;
}
.tr {
    display:table-row;
    height:28px;
}
.td {
    display:table-cell;
}
.td1 {
    width:200px;
}
.td2 {
    width:130px;
}
.td3 {
    width:400px;
}
</style>
</head>

<body>
<div class="table">
    <div class="tr">
        <div class="td td1">
            <input type="radio" name="section1a" id="radio1-1" value="radio" />
            <label class="large black" for="radio1-1">Project</label>
        </div>
        <div class="td td2"> <span class="large black">Ref:</span> 
        </div>
        <div class="td td3">
            <input id="txtRef" class="form-textbox" name="ref" type="text" placeholder="Insert project reference" />
        </div>
    </div>
    <div class="tr">
        <div class="td td1"></div>
        <div class="td td2"> <span class="large black">Title:</span> 
        </div>
        <div class="td td3">
            <input id="txtTitle" class="form-textbox" name="title" type="text" placeholder="Insert project title" />
        </div>
    </div>
    <div class="tr">
        <div class="td td1">
            <input type="radio" name="section1a" id="radio1-2" value="radio" />
            <label class="large black" for="radio1-2">Account</label>
        </div>
        <div class="td td2"> <span class="large black">Name:</span> 
        </div>
        <div class="td td3">
            <input id="txtName" class="form-textbox" name="name" type="text" placeholder="Insert account name" />
        </div>
    </div>
    <div class="tr">
        <div class="td td1">
            <input type="radio" name="section1a" id="radio1-3" value="radio" />
            <label class="large black" for="radio1-3">General Business</label>
        </div>
        <div class="td td2"></div>
        <div class="td td3">
            <input class="form-textbox" name="organization" type="text" placeholder="Insert client organisation name" />
        </div>
    </div>
</div>

<script>
var rbProject = document.getElementById('radio1-1');
var rbAccount = document.getElementById('radio1-2');
var txtRef = document.getElementById('txtRef');
var txtTitle = document.getElementById('txtTitle');
var txtName = document.getElementById('txtName');


rbProject.addEventListener('change', function (e) {
    txtRef.disabled = false;
    txtTitle.disabled = false;
    txtName.disabled = true;
})

rbAccount.addEventListener('change', function (e) {
    txtRef.disabled = true;
    txtTitle.disabled = true;
    txtName.disabled = false;
})
</script>


</body>


</html>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

不知道为什么这不起作用

来自分类Dev

我的axios实例不起作用,我也不知道为什么

来自分类Dev

我的Matlab代码不起作用,但我不知道为什么?

来自分类Dev

我不知道为什么我的 backgroundImage 不起作用

来自分类Dev

我不知道为什么我的“if”语句不起作用

来自分类Dev

我的 gridsearchCV 不起作用,我不知道为什么

来自分类Dev

我不知道为什么这段代码不起作用(空指针异常)

来自分类Dev

我不知道为什么这个static_assert()代码不起作用

来自分类Dev

我不知道为什么此联系表格不起作用

来自分类Dev

存储过程不起作用,我也不知道为什么

来自分类Dev

clearInterval()不起作用,我不知道为什么

来自分类Dev

我不知道为什么这个 FFmpeg 命令在 android 中不起作用?

来自分类Dev

不知道为什么我的循环功能在这里不起作用

来自分类Dev

Hibernate Validator 不起作用,但我不知道为什么

来自分类Dev

SKAction.moveBy 不起作用,我不知道为什么

来自分类Dev

列表理解逻辑不起作用,我不知道为什么

来自分类Dev

中断功能在Python 3.5中不起作用!我不知道为什么。我需要建议

来自分类Dev

我正在尝试进行此sql更新查询,但我不知道为什么它不起作用

来自分类Dev

jQuery隐藏/显示div从选择框不起作用,我不知道为什么吗?

来自分类Dev

我不知道为什么这个for循环程序不起作用(python)。解决方案?

来自分类Dev

不知道为什么聚合物不起作用

来自分类Dev

不知道为什么这个jquery帖子不起作用

来自分类Dev

primefaces GMap示例不起作用,也不知道为什么

来自分类Dev

不知道为什么这个JQuery动画不起作用

来自分类Dev

不知道为什么正则表达式不起作用

来自分类Dev

文件打开提示功能代码不起作用-不知道为什么

来自分类Dev

本地存储不起作用?不知道为什么

来自分类Dev

代码行不起作用。不知道为什么吗

来自分类Dev

不知道为什么jQuery find()方法不起作用

Related 相关文章

  1. 1

    不知道为什么这不起作用

  2. 2

    我的axios实例不起作用,我也不知道为什么

  3. 3

    我的Matlab代码不起作用,但我不知道为什么?

  4. 4

    我不知道为什么我的 backgroundImage 不起作用

  5. 5

    我不知道为什么我的“if”语句不起作用

  6. 6

    我的 gridsearchCV 不起作用,我不知道为什么

  7. 7

    我不知道为什么这段代码不起作用(空指针异常)

  8. 8

    我不知道为什么这个static_assert()代码不起作用

  9. 9

    我不知道为什么此联系表格不起作用

  10. 10

    存储过程不起作用,我也不知道为什么

  11. 11

    clearInterval()不起作用,我不知道为什么

  12. 12

    我不知道为什么这个 FFmpeg 命令在 android 中不起作用?

  13. 13

    不知道为什么我的循环功能在这里不起作用

  14. 14

    Hibernate Validator 不起作用,但我不知道为什么

  15. 15

    SKAction.moveBy 不起作用,我不知道为什么

  16. 16

    列表理解逻辑不起作用,我不知道为什么

  17. 17

    中断功能在Python 3.5中不起作用!我不知道为什么。我需要建议

  18. 18

    我正在尝试进行此sql更新查询,但我不知道为什么它不起作用

  19. 19

    jQuery隐藏/显示div从选择框不起作用,我不知道为什么吗?

  20. 20

    我不知道为什么这个for循环程序不起作用(python)。解决方案?

  21. 21

    不知道为什么聚合物不起作用

  22. 22

    不知道为什么这个jquery帖子不起作用

  23. 23

    primefaces GMap示例不起作用,也不知道为什么

  24. 24

    不知道为什么这个JQuery动画不起作用

  25. 25

    不知道为什么正则表达式不起作用

  26. 26

    文件打开提示功能代码不起作用-不知道为什么

  27. 27

    本地存储不起作用?不知道为什么

  28. 28

    代码行不起作用。不知道为什么吗

  29. 29

    不知道为什么jQuery find()方法不起作用

热门标签

归档