dso15221 2015-12-05 09:10
浏览 236
已采纳

jquery上的click事件不起作用[重复]

This question already has an answer here:

I have printed an echo with php of input element and I need to get click event id using jquery. Below is the code I am trying to get

API.php(echo element to index.php using ajax):

echo"<input type='submit' id='something' value='accept me'/>";

index.php(need to get the id='something' in click event):

$("#something").click(function(){
    alert("hi");
    //doesnt work 
});

why it is not working? Please suggest

</div>
  • 写回答

4条回答 默认 最新

  • douju8782 2015-12-05 09:29
    关注

    Write onclick() function on input itself. It will work.

    For more info, click Add Onclick On Submit Button - Stack Overflow

    <form ... >
        .
        .
        <input type='submit' id='something' onclick="return showValue();" value='accept me'/>
    </form>
    
    <script>
    function showValue() {
        alert('hi');
        return false;
    }
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?