Javascript call problem

1:
<script>
    $(function () {
        var $butObj = $("-sharpbutObj");
        $butObj.click(function () {
            var $uname = $("-sharpuserName");
            var inputName = $uname[0];
            alert(inputName.value);
        });
    })
</script>
2:
    <script>
        var $butObj = $("-sharpbutObj");
        $butObj.click(function () {
            var $uname = $("-sharpuserName");
            var inputName = $uname[0];
            alert(inputName.value);
        });
</script>

<body>
    :
    <input type="text" id="userName">
    <input type="button" id="butObj" value="">
</body>
clickclick
Mar.02,2021

html is executed sequentially before the dom is rendered before your script is executed, so the second one is not bound with click time. Jq's dollar method is actually very similar to onload, which is performed after dom rendering, so the first way is to find the dom node and bind the click event


isn't it the same for you? is it my poor eyesight?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eab21e-47e07.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eab21e-47e07.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?