0
<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>

在上面的代码中,没有任何事件在起作用,并且 jquery hide() 事件在没有包含 jquery 的情况下起作用。我不知道问题,请帮助!

4

2 回答 2

3

我猜你绑定它们事件的元素还没有在 dom 上。请加

$(document).ready(function(){//place you events bind here});
于 2013-09-15T06:32:00.383 回答
2

看来你改变了这个

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

例子

$('#'+ele.id).hide();  // and every where
于 2013-09-15T06:41:07.677 回答