duanjiang7505 2013-09-15 06:29
浏览 30
已采纳

javascript中的事件无法正常工作

<html>
<head>
    <link href="admin.css.css" rel="stylesheet" type="text/css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript" ></script>
    <script type="text/javascript">
    function hello(ele)
    {
        //alert(ele);
        $("#text"+ele.id).show();
        //alert(ele);
        $(ele.id).hide();
        if(typeof $(ele.id).addEventListener != 'undefined')
            {
                $(ele.id).addEventListener("keyup", printhello, false)
            }
        else if(typeof $(ele.id).attachEvent != 'undefined')
            {
                $(ele.id).attachEvent("onkeyup",printhello);
            }

        function printhello()
        {
            alert("hello");
        }
    }
</script>
</head>
<div class="content">
<?php
$conn = mysqli_connect("localhost","root","","fashion");
if(!$conn)
{
    die("connection not made ". mysqli_error($conn));
}
$query="select * from styles";
$result=mysqli_query($conn,$query);
if(mysqli_num_rows ($result)>0)
{
    $str="<table class='styles-table'><th>id</th><th>name</th><th>image</th>";
    while($dr=  mysqli_fetch_array($result))
    {
        $str .= "<tr><td>".$dr["id"]."</td><td><input type='textbox'     id='text".$dr["id"]."' style='display:none;' value='".$dr["name"]."' /><div ondblclick='hello(this)' style='border:solid 2px black;' id='".$dr["id"]."'>".$dr["name"]."</div></td><td>".$dr["image1"]."</td></tr>" ;
    }
}
echo($str);
?>
</div>
</html>

In the above code no event is working, and the jquery hide() event is working without even including jquery. i don't know the problem , please help!

  • 写回答

2条回答 默认 最新

  • dongpu1908 2013-09-15 06:41
    关注

    Its seems you change this

    $(ele.id) to $('#'+ele.id)

    Example

    $('#'+ele.id).hide();  // and every where
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程