首页 > 代码库 > js选择器 querySelector

js选择器 querySelector

<form method="post" action="" id="myform">
<input type="button" value="submit">
</form>
<script type="text/javascript">
function init(){
    var submitBtn=document.querySelector("input[value=http://www.mamicode.com/submit]");
    submitBtn.addEventListener("click",function(){
        var form=document.getElementById("myform");
        alert(form.id);
        form.submit();
    })
}
init();
</script>