我正在为我的项目使用 bootsrtap。当我在 javascript 中使用 innerHtml 替换某些部分时,它将不起作用。
<div id="confirm_body">
<div class="modal-body">
<p>Enter the email configured in your profile. A password reset link will be sent to by email. </p>
<label>User Name</label>
<input class="login-class" type="text" name="username" id="username" size="30"/>
<label>Enter email address</label>
<input class="login-class" type="text" name="emailAdd" id="emailAdd" size="30"/>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary" id="sendConfMail">Submit</button>
</div>
</div>
但是在我替换这个使用javascript之后,
document.getElementById('sendConfMail').onclick=function(){
document.getElementById('confirm_body').innerHTML='<div class="modal-body"><div class="alert alert-success"> Your confirmation email sent! </div> </div><div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">Close</button></div>';
};
之后,当我单击 ID=sendConfMail 的按钮时,什么也没发生。为什么是这样?