通过innerHTML向文档中插入的script代码是不会自动执行的,这个时候就需要我们通过代码来手动执行。
document.body.innerHTML = data.data; var scripts = document.body.getElementsByTagName("script"); for(var i=0;i<scripts.length;i++){ //一段一段执行script eval(scripts[i].innerHTML); }
data.data:
<form id='alipaysubmit' name='alipaysubmit' action='https://mapi.alipay.com/gateway.do?_input_charset=utf-8' method='get'>
<input type='hidden' name='_input_charset' value='utf-8'/>
<input type='hidden' name='app_pay' value='Y'/>
<input type='hidden' name='body' value='测试商品'/>
<input type='hidden' name='notify_url' value='http://v1.ebbaba.com/admin/notify.aspx'/>
<input type='hidden' name='out_trade_no' value='20161021084255214384726'/>
<input type='hidden' name='partner' value='2088421505809545'/>
<input type='hidden' name='payment_type' value='1'/>
<input type='hidden' name='return_url' value='http://wx.ebbaba.com/index-1.html'/>
<input type='hidden' name='seller_id' value='2088421505809545'/><input type='hidden' name='service' value='alipay.wap.create.direct.pay.by.user'/>
<input type='hidden' name='show_url' value='http://wx.ebbaba.com/ProductDetail.html?id=218'/>
<input type='hidden' name='subject' value='测试商品'/>
<input type='hidden' name='total_fee' value='0.01'/>
<input type='hidden' name='sign' value='gRASXfc72RDrUKHq+e1mfvxbNOi3y73lKhME7wJkJkwdPqI8nPqnFXmFc6O71jtEM2H9vLIpm3y2r2p8cTNGIuwKTqAOhLcljj/p2ddBY4ObvunUK+OjcwpKUCCfUS+PAmyb+Xp0DoQA7WTPzLzcpz7g6IwfaoAmnAEaz8F5djw='/>
<input type='hidden' name='sign_type' value='RSA'/>
<input type='submit' value='确认' style='display:none;'>
</form>
<script>
document.forms['alipaysubmit'].submit();
</script>