模糊事件上的Javascript

模糊事件上的Javascript,javascript,onblur,Javascript,Onblur,我有以下代码: <span style="margin:0px 2px 0px 2px;"> <asp:Label ID="labelPromptText" runat="server" Text="Selected Location:" /> <span id="spanSelectedLocation" style="padding:2px 2px 2px 2px; cursor:pointer;" onmouseover="javascript

我有以下代码:

<span style="margin:0px 2px 0px 2px;">
    <asp:Label ID="labelPromptText" runat="server" Text="Selected Location:" />
    <span id="spanSelectedLocation" style="padding:2px 2px 2px 2px; cursor:pointer;" onmouseover="javascript:SetBackgroundColor('spanSelectedLocation', '#E0E0E0');" onmouseout="javascript:SetBackgroundColor('spanSelectedLocation', '#FFFFFF');" onclick="ControlLocationsVisibility();">
        <asp:Label ID="labelDisplay" runat="server" Text="None" Font-Bold="True" />
        <img alt="Click to change" src="Images/downArrow.png" />
    </span>
</span>

<asp:Panel ID="panelLocations" runat="server" DefaultButton="buttonFindLocation" style="position:absolute;border:solid 1px #E0E0E0;padding:10px 5px 5px 10px;background-color:#F7F7F7;width:350px;display:none;" >
    Search: <asp:TextBox ID="textboxLocationSearch" runat="server" />

    <asp:Button ID="buttonFindLocation" runat="server" Text="Find" OnClick="buttonFindLocation_Click" />

    <input type="button" value="Cancel" onclick="javascript:ControlLocationsVisibility();"

    <hr />

    <asp:TreeView ID="TreeViewLocations" runat="server" OnSelectedNodeChanged="TreeViewLocations_SelectedNodeChanged" NodeIndent="10"></asp:TreeView>
</asp:Panel>

搜索:

如果您使用setTimeout()和clearTimeout(),您可以像前面提到的那样使用blurevent,但是当面板中的任何内容获得焦点时,请清除超时。这样,事件执行的唯一时间将是它“真正”失去焦点的时间。

如果使用setTimeout()和clearTimeout(),您可以像前面提到的那样使用blurevent,但当面板中的任何内容获得焦点时,请清除超时。这样,事件执行的唯一时间就是它“真的”失去焦点的时候。

你的另一个选择是处理身体上的onclick事件,但这可能会很快变慢。如果你要走这条路,它看起来会是这样的:

<html>
 <head>
  <title>Hide Test</title>
 </head>
 <body>
  <div id="first">
    <p>This is the first div.</p>
  </div>
  <div id="second">
    <p>This is the second div.</p>
  </div>
  <script type="text/javascript">
  var first = document.getElementById("first");
  var second = document.getElementById("second");
  var isChildOf = function (ele, parent) {
    if (ele.parentNode === null) {
        return false;
    } else if (ele.parentNode === parent) {
        return true;
    } else {
        return isChildOf(ele.parentNode, parent);
    }
  };
  document.body.onclick = function(e) {
    if (isChildOf(e.target, second)) {
        console.log("Hiding second.");
        second.style.display = 'none';
    } else {
        console.log("Showing second.");
        second.style.display = 'block';
    }
  };
  </script>
 </body>
</html>

隐藏测试
这是第一组

这是第二组

var first=document.getElementById(“first”); var second=document.getElementById(“second”); var isChildOf=函数(元素,父项){ if(ele.parentNode==null){ 返回false; }else if(ele.parentNode==父节点){ 返回true; }否则{ 返回isChildOf(ele.parentNode,parent); } }; document.body.onclick=函数(e){ if(isChildOf(如目标,秒)){ log(“隐藏第二个”); second.style.display='none'; }否则{ console.log(“显示秒”); second.style.display='block'; } };
另一种选择是处理身体上的onclick事件,但这可能会很快变慢。如果你要走这条路,它看起来会是这样的:

<html>
 <head>
  <title>Hide Test</title>
 </head>
 <body>
  <div id="first">
    <p>This is the first div.</p>
  </div>
  <div id="second">
    <p>This is the second div.</p>
  </div>
  <script type="text/javascript">
  var first = document.getElementById("first");
  var second = document.getElementById("second");
  var isChildOf = function (ele, parent) {
    if (ele.parentNode === null) {
        return false;
    } else if (ele.parentNode === parent) {
        return true;
    } else {
        return isChildOf(ele.parentNode, parent);
    }
  };
  document.body.onclick = function(e) {
    if (isChildOf(e.target, second)) {
        console.log("Hiding second.");
        second.style.display = 'none';
    } else {
        console.log("Showing second.");
        second.style.display = 'block';
    }
  };
  </script>
 </body>
</html>

隐藏测试
这是第一组

这是第二组

var first=document.getElementById(“first”); var second=document.getElementById(“second”); var isChildOf=函数(元素,父项){ if(ele.parentNode==null){ 返回false; }else if(ele.parentNode==父节点){ 返回true; }否则{ 返回isChildOf(ele.parentNode,parent); } }; document.body.onclick=函数(e){ if(isChildOf(如目标,秒)){ log(“隐藏第二个”); second.style.display='none'; }否则{ console.log(“显示秒”); second.style.display='block'; } };
ya,我真的不想走这条路,因为代码在ASP.Net用户控件中,将在整个网站上使用,我不能让其他用户将所有这些都放在他们的代码中,放在他们页面的每个项目上ya,我真的不想走这条路,因为代码在ASP.Net用户控件中,将在整个网站上使用,我不能让其他用户将所有这些都放在他们页面的每个项目上,你能给我一点例子吗?你能给我一点例子吗?