gpt4 book ai didi

javascript - 如何在单击某个单选按钮后禁用复选框。

转载 作者:行者123 更新时间:2023-11-28 20:15:37 25 4
gpt4 key购买 nike

想要在选择“3D”单选按钮后禁用“动画”复选框。一旦选择“2D”,也无法禁用。

html代码

  <script type="text/x-handlebars" id="createProject">
<div class="projectForm">
<table cellpadding="10">
<tr>
<td> Project Name </td>
<td> <input type="text" name="projectName" /> </td>
</tr>
<tr>
<td> Project Description </td>
<td> <textarea name="projectDesc" > </textarea> </td>
</tr>
<tr>
<td> Pipleline Type </td>
<td>
<input type="radio" name="pipelineType" value="2d" id="2d" checked="checked" onclick="displayType"> 2D Pipleline <br>
<input type="radio" name="pipelineType" value="3d" id="3d" onclick="displayType"> 3D Pipleline </td>
</tr>
<tr>
<td> Project Roles </td>
<td> <input type="checkbox" name="projectRoles" id="animation"value="Animation Clean Up"> Animation Clean Up
<input type="checkbox" name="projectRoles" value="Background Painting"> Background Painting
<input type="checkbox" name="projectRoles" value="Casting & Recording"> Casting & Recording
<input type="checkbox" name="projectRoles" value="Color Styling"> Color Styling
</td>
</tr>
</table>
</div>

</script>

我是 ember.js 的新手,我在 app.js 中有 java 代码。如果放在另一个js文件中会不会更好?

java脚本

function displayType() {

if(document.getElementById('2d').checked) {
document.getElementById('animation').disabled = false;
}
else {
document.getElementById('animation').disabled=true;
}
}

任何建议都会非常有帮助。谢谢。

最佳答案

我注意到的第一件事是您忘记将 onclick 调用转换为函数调用:

onclick="displayType"

需要更改为

onclick="displayType()"

接下来,当我将你的代码放入jsfiddle时,它没有找到该函数,因为它不在全局范围内。当我更改函数定义时:

function displayType() {

至:

window.displayType = function () {

解决了这个问题。这可能会有所不同,具体取决于您放置代码的位置。

关于javascript - 如何在单击某个单选按钮后禁用复选框。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19239466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com