javascript 无法在 IE 中使用单选按钮 onClick 工作

标签 javascript internet-explorer onclick radio-button

我有一些代码充当重定向并在用户单击单选按钮时设置一些值。在 Chrome 和 Firefox 中,这些脚本可以完美运行,但在 IE 中似乎什么也没有发生。

HTML

<td>
    <input type='radio' id="order_type6" name='order_type' value="5"
        onClick="selectOrderType('1')">
    <label for="order_type6"><strong>Facility Employee</strong></label>
</td>
<td>
    <input type='radio' id="order_type7" name='order_type' value="5" 
        onClick="selectOrderType('1')">
    <label for="order_type7"><strong>Private Contract</strong></label>
</td>

JS函数:

function selectOrderType(type)
{
    console.log(type);
   //replace '&load=1' with '&neworder=1'
    $location = window.location.href.replace(/&load\=1/,'&neworder=1#');
   //replace '#' at the end of the string with '' + $ordertype
    window.location.href = $location.replace(/#?$|&order_type\=\D?/,'&order_type='+type);
}

最佳答案

删除console.log - 或按F12 打开控制台。

IE不打开的话不支持console

'console' is undefined error for Internet Explorer

或者更改为window.console && console.log(type)

关于javascript 无法在 IE 中使用单选按钮 onClick 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12863498/

相关文章:

javascript - 使用 momentjs 保存为 UTC 并显示为本地时间

javascript - SweetAlert2 确认后禁用外部点击

css - Internet Explorer 破坏了页脚,是的,我试过粘性页脚

jquery - 我做了什么让 IE 生气了?

javascript onclick 不工作?

javascript - 使用 d3js 的 onclick 在新选项卡中绘制图表

javascript - json javascript : escape double quotes? concat json 与其他字符串

javascript - Skrollr 只运行一次动画然后停止

javascript - 页面重定向上的 Microsoft Jscript 运行时错误 - asp.net 和 javascript

javascript - Jquery If/Then 在 Click 函数中?