我使用ASP.Net MVC 1目前正在建设一个网站,并使用this JavaScript文件,以便与图像替换默认的单选按钮。我正在使用单选按钮在jQuery .toggle之间切换两种形式。IE7不调用JavaScript的onclick
这工作完全在火狐,Chrome,Safari和IE8,但不会在IE7在所有的工作。但是,如果我使用IE的开发人员工具检查代码并在运行时在onclick方法中添加一个空格,它就可以工作。
我不知道这是为什么,我已经试过jQuery的,常规的JavaScript的各种组合,使用返回false;许多变化都无济于事。
如果任何人都可以摆脱任何光线,这将是大加赞赏。下面的相关代码。
的Javascript:
var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
for (a = 0; a < inputs.length; a++) {
if (inputs[a].type == "radio" && inputs[a].className == "styled") {
span[a] = document.createElement("span");
span[a].className = inputs[a].type;
span[a].setAttribute("onclick", inputs[a].getAttributeNode("onclick").nodeValue);
if (inputs[a].checked == true) {
position = "0 -" + (radioHeight * 2) + "px";
span[a].style.backgroundPosition = position;
}
inputs[a].parentNode.insertBefore(span[a], inputs[a]);
inputs[a].onchange = Custom.clear;
if (!inputs[a].getAttribute("disabled")) {
span[a].onmousedown = Custom.pushed;
span[a].onmouseup = Custom.check;
} else {
span[a].className = span[a].className += " disabled";
}
}
}
代码:
<%=Html.RadioButton("rbCustomerSelect", true,Model.IsNewCustomer.GetValueOrDefault(false),new { id="NewCustomerRadioButton", @class="styled", onclick="ShowNewCustomerForm(true);" })%>
这是呈现为:
<span class="radio" style="background-position: 0px -50px;" onclick="ShowNewCustomerForm(true);"/>
添加空格之前单击收音机时是否出现JavaScript错误?也许在解释时间?下一个明显的问题是,为什么不只是让服务器返回跨度而不是输入? – 2011-01-27 03:26:19
根本没有javascript错误。至少没有被抓到。 – Steve 2011-01-27 03:42:50