<script type="text/html" id="test">加载后如何引用js

参照weui的路由模式,我创建了type="text/html"模板进行跳转


//html
<script type="text/html" id="tpl_list">...</script>
//跳转
window.location.href = "#list"

我现在能正常引用type="text/html"模板,在tpl_list这个模板里面我需要点击input跳转新的页面

//html
<input id="search_list" type="text">

//js
$("#search_list").bind('keypress', function (event) {
    console.log(event);
    if (event.keyCode == "13") {
        console.log(1);
        window.location.href = "#button"
    }
});

但是js正常写,跳转到tpl_list后,点击input无响应,此时手动刷新网页,点击input才有跳转效果
请问有什么解决办法吗?

阅读 3.9k
1 个回答

你用DOM操作就必须加载完才能操作,你使用vue就应该把事件绑定到模板的具体元素上

@keyup.enter.native="submit"
submit(){
  window.location.href = "#button"
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题