[英]On Click Event is not working in Chrome and FireFox, but works fine in the IE browers
I want the user to click on a td in a table to call a javascript function, but its working fine in the IE, but not in the chrome and firefox browser. 我希望用户单击表中的td来调用javascript函数,但是它在IE中可以正常工作,但在chrome和firefox浏览器中却不能。
<td id="tdMon" class="space15" style="cursor: pointer;" onclick="HandleClick1(this);">
<div id="dvDay1" runat="server">
<div class="booking-day">
<asp:Label ID="lblDay1" runat="server" Text=""></asp:Label>
<asp:LinkButton ID="lnk1" runat="server" Text="" OnClick="lnk1_Click" CommandName="click"
CommandArgument=""></asp:LinkButton>
| 
<asp:Label ID="lblhr1" runat="server" Text="-- hr(s)" ForeColor="red"></asp:Label>
</div>
</div>
</td>
-- bottow of the page -- -页面底部-
<script language='javascript' type='text/javascript'>
function HandleClick1(objTD) {
var lnk = objTD.getElementsByTagName("a");
if (lnk[0].disabled == false)
document.getElementById('<%=btn1.ClientID %>').click();
else
return false;
}
</script>
It's a bad idea to have inline functions/styles. 具有内联函数/样式是一个坏主意。 Taking into account you already have an ID for your td:
考虑到您已经拥有您的td的ID:
function init(){
document.getElementById('tdTue').onclick=function(){};
}
window.onload=init;
If you want to go for something like jquery, this is probably a better model. 如果您想使用类似jquery的东西,这可能是一个更好的模型。 I'm sure the function was just an example.
我确定该功能只是一个例子。 This only triggers a click on TDs that have a data-link-rel attribute and it searches for the equivalent link.
这仅触发对具有data-link-rel属性的TD的单击,并搜索等效的链接。
$(function () {
$("table").on("click", "td[data-link-rel]", function () {
var linkRel = $(this).data("link-rel"),
selector = "a[data-link=" + linkRel + "]";
$(selector).trigger('click');
});
$("a").on("click", function () {
$("<li> I clicked on " + $(this).text() + "</li>").appendTo('ul');
});
});
JSFiddle with markup: http://jsfiddle.net/D8yg9/ 带有标记的JSFiddle: http : //jsfiddle.net/D8yg9/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.