外部文件上的Javascript
var oldgridSelectedColor;
function setMouseOverColor(element)
{
oldgridSelectedColor = element.style.backgroundColor;
element.style.backgroundColor='#C0C0C0';
element.style.cursor='hand';
//element.style.textDecoration='underline';
}
function setMouseOutColor(element)
{
element.style.backgroundColor=oldgridSelectedColor;
element.style.textDecoration='none';
}
function setMouseDownColor(element) {
oldgridSelectedColor = element.style.backgroundColor;
element.style.backgroundColor = 'Green';
element.style.cursor = 'hand';
//element.style.textDecoration='underline';
}
function setMouseUpColor(element) {
element.style.backgroundColor = 'Green';
element.style.textDecoration = 'none';
}
aspx中的rowdatabound事件
protected void grdTenant_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Style["display"] = "none";
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "javascript:setMouseOverColor(this);";
e.Row.Attributes["onmouseout"] = "javascript:setMouseOutColor(this);";
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.grdTenant, "Select$" + e.Row.RowIndex);
e.Row.ToolTip = "Click the row to edit.";
}
这些是我正在使用的代码,它们工作得很好,直到我更改了我的gridview设置,并使用新的jquery命令来修复gridview标头。一些js命令在我注入新脚本后也停止工作,并且能够使用 jquery.noConflict()代码修复它们。我用该值声明变量并且一切都运行良好(如某些人所提到的)当你在一个页面中有多个javascript代码或库时,该怎么做。
然而,有了这个,我无法修复,因为javascript代码中没有$命令。我有点迷茫。任何帮助将不胜感激。
答案 0 :(得分:0)
试试这个, Javascript:
<script type="text/javascript"> jQuery.noConflict() </script>
function MouseEvents(objRef, evt) {
if (evt.type == "mouseover") {
objRef.style.cursor = 'pointer';
objRef.style.backgroundColor = "green";
}
else {
if (evt.type == "mouseout") objRef.style.backgroundColor = "blue";
}
}
</script>
代码隐藏
protected void grdTenant_RowDataBound(object sender,
System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "MouseEvents(this, event)");
e.Row.Attributes.Add("onmouseout", "MouseEvents(this, event)");
}
}