在 JavaScript 中更改多个值时遇到问题
Trouble changing multiple values in javascript
好吧,我遇到了一个问题。我正在修改 ATS 系统,需要添加一些功能,但我在 JavaScript 中遇到了一件奇怪的事情。基本上,我需要根据下拉菜单中的选择更改一组表单值,并且代码有效...当只有一件事要改变时。当我添加需要更改它的其他部分时,它停止工作。我已经跑遍了互联网和许多 Stack 问题,但似乎没有任何帮助。有效的代码是:
<form id="test" name="test">
<select id="statusID" name="statusID" onchange="javascript: return updateForm();">
<option value="" selected></option>
<option value="test1">One</option>
<option value="2">Two</option>
</select>
<br />
<input type="hidden" value="Test" id="RS" name="RS" />
</form>
<script type='text/javascript'>
function updateForm()
{
if (document.getElementById('statusID').selectedIndex == "2")
document.getElementById('RS').value = '200'
else if(document.getElementById('statusID').selectedIndex == "1")
document.getElementById('RS').value = 'RSP'
}
</script>
当我在服务器上测试它时,这有效,但当我添加需要填充的其他字段时,它完全停止工作。我正在使用的JavaScript如下。我已经根据我看到的代码尝试了一些变体,但无济于事。
<script type='text/javascript'>
function updateForm()
{
if (document.getElementById('statusID').selectedIndex == "2")
document.getElementById('RS').value = '200'
document.getElementById('RSDATE').value = '200'
document.getElementById('RSP').value = '200'
else if(document.getElementById('statusID').selectedIndex == "1")
document.getElementById('RS').value = 'RSP'
document.getElementById('RSDATE').value = 'RSP'
document.getElementById('RSP').value = 'RSP'
}
</script>
我应该指出,我根本不精通JavaScript。我也不精通PHP...但我正在修改基于 PHP 的 ATS 系统。这段代码是我和目标(完成ATS系统)之间的倒数第二个块,因此将不胜感激。
从问题的上下文来看,您应该在 if 和 else if 后面添加大括号:(战斗也注意到,应添加分号)
if (document.getElementById('statusID').selectedIndex == "2") {
document.getElementById('RS').value = '200';
document.getElementById('RSDATE').value = '200';
document.getElementById('RSP').value = '200';
}
else if(document.getElementById('statusID').selectedIndex == "1") {
document.getElementById('RS').value = 'RSP';
document.getElementById('RSDATE').value = 'RSP';
document.getElementById('RSP').value = 'RSP';
}
您需要在每行末尾使用分号,并且每个条件都需要大括号。
function updateForm() {
if (document.getElementById('statusID').selectedIndex == "2") {
document.getElementById('RS').value = '200';
document.getElementById('RSDATE').value = '200';
document.getElementById('RSP').value = '200';
}
else if (document.getElementById('statusID').selectedIndex == "1") {
document.getElementById('RS').value = 'RSP';
document.getElementById('RSDATE').value = 'RSP';
document.getElementById('RSP').value = 'RSP';
}
}
当您要执行操作块时,条件后需要跟括号。例如:
if (document.getElementById('statusID').selectedIndex == "2") {
document.getElementById('RS').value = '200'
document.getElementById('RSDATE').value = '200'
document.getElementById('RSP').value = '200'
}
相关文章:
- 将PHP变量传递给jQuery时遇到问题
- 将jQuery转换为用户脚本的普通Javascript时遇到问题
- 将子文档推送到父数组时遇到问题
- JQuery FullCalendar在从ajax成功调用rerenderEvents时遇到问题
- 在将javascript附加到我的html中时遇到问题
- 为什么我在以编程方式打开窗口时遇到问题
- 在将缩略图链接到模态时遇到问题
- 使用 ng 模型获取数据时遇到问题
- 是否有其他人在设计Twitter Typeahead时遇到问题'的搜索栏
- 使用jquery进行整数比较时遇到问题
- 使用PhantomJS下载动态web内容时遇到问题
- 设置RequireJS时遇到问题
- 让Javascript在SharePoint 2010上运行时遇到问题
- I'我在react.js中编写for循环时遇到问题
- 通过jQuery获取上传的文件名时遇到问题
- 我在启动我的节点时遇到问题.js IRC 机器人
- Ruby on Rails 4:在 Rails Web 应用程序中添加 Javascript 文件时遇到问题
- 从谷歌地图自定义控件打开离子模态时遇到问题
- 在使用 YAML 和 Google App Engine 时遇到问题
- 在 Chrome 扩展程序中将鼠标悬停在广告上使用时遇到问题