Javascript不能在所有浏览器中工作
javascript not working in all browsers
我看遍了所有的地方,并尝试了各种脚本,但我一直遇到同样的问题。
我试图禁用或隐藏提交按钮,直到复选框被选中。
我遇到的问题是,除非我打开兼容性,否则在IE10中没有任何工作,并且大多数时候它们在FF 20.0.1中不起作用。
这是我到目前为止尝试过的。
<input type="checkbox" name="agree" value="yes" onclick="agreed.disabled = !this.checked" />Do you Agree?
<input type="submit" name="agreed" id="agreed" value="{L_AGREE}" class="button1" disabled="disabled" />
<script type="text/javascript">
function checkSubmit(ele, id) {
x = document.getElementById(id);
if (ele.checked == true) x.disabled = false;
else x.disabled = true;
}
</script>
<input type="checkbox" name="myCheck" onclick="checkSubmit(this, 'agreed')" value="y" />Do you Agree?
<input type="submit" name="agreed" id="agreed" value="{L_AGREE}" class="button1" disabled="disabled" />
<script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
$("#terms").click(function() {
if ($(this).is(':checked')) {
$('#agreed').removeAttr('disabled');
} else {
$('#agreed').attr('disabled', 'disabled');
}
});
});//]]>
</script>
<input type="checkbox" class="required" id="terms"/>Do you Agree?
<input type="submit" name="agreed" id="agreed" value="{L_AGREE}" class="button1" disabled="disabled" />
我已经尝试了许多其他方法,但仍然遇到IE10或FF的问题。
我需要的是帮助得到一些工作在所有的浏览器
第一个例子更可能在某些浏览器上工作,而不是其他浏览器,这取决于它们是通过它们的ID将元素放在window
还是document
对象上。
使用document.getElementById()
修复。
<input type="checkbox" name="agree" value="yes" onclick="document.getElementById('agreed').disabled = !this.checked" />Do you Agree?
<input type="submit" name="agreed" id="agreed" value="{L_AGREE}" class="button1" disabled="disabled" />
第二个函数应该在任何浏览器中工作,只要该函数是全局的,尽管你可以缩短它。
function checkSubmit(ele, id) {
document.getElementById(id).disabled = !ele.checked;
}
相关文章:
- 如何使用modalDialog来显示可以在所有浏览器中工作的弹出窗口
- Javascript的某些部分在Chrome中不起作用,但在其他浏览器中可以完美工作
- 如何隐藏空<span>在IE中使用javascript.(注意,在其他浏览器中工作正常)
- Javascript字母选择没有'我不能在谷歌浏览器上工作
- 我如何使HTML5<输入类型=月份>以在所有浏览器上工作
- 我的时间倒计时脚本在谷歌浏览器中工作正常,但在其他浏览器中打开时它显示为南楠
- 使用一个Javascript函数提交多个表单可以在FF中工作,而不需要其他浏览器
- Json到CSV下载,可以在chrome中工作,但不能在IE浏览器中工作
- 有没有人能够得到这个要求或调试NPM模块在浏览器中工作
- 是否可以在浏览器中创建类似谷歌浏览器工作区的东西
- JAX-RS Web Service 通过浏览器工作,但不通过 XMLHTTPRequest
- 如何使旋转图像与javascript跨浏览器工作
- jQuery:如何使css('line-height')跨浏览器工作
- 填写用户名和密码后,当我按下一个回车键无法登录ie,但谷歌浏览器工作正常.如何来
- 未捕获的语法错误与jquery插件和chrome,在其他浏览器工作正常
- Javascript函数不能跨浏览器工作
- 如何将all()函数转换为跨浏览器工作
- indexOf在IE8抛出错误,但在所有其他浏览器工作
- 缓存破坏不与android浏览器工作
- JS播放器——错误:我的返回错误不与IE10工作,但与所有其他浏览器工作