gpt4 book ai didi

backbone.js - Backbone JS 按钮单击事件不起作用

转载 作者:行者123 更新时间:2023-12-01 02:04:15 24 4
gpt4 key购买 nike

我是主干 js 的新手,当单击 html 页面中显示的按钮时,我正在努力显示警报。我确信我在做一些愚蠢的事情,但是当我单击按钮时,事件似乎没有被触发。我试图在事件部分同时使用提交和点击,但我似乎无法让它工作。如果有人可以帮助我,我将不胜感激,谢谢!

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Event Test</title>
<script src="../../external/jquery.js"></script>
<script src="../../external/underscore.js"></script>
<script src="../../external/backbone.js"></script>
</head>
<body>
<div id="standard-input-form"></div>
<script>

var MovePalletView = Backbone.View.extend({
initialize: function() {
},

events: {
'submit' : 'move'
},

render: function(event) {
this.$el.append('<button type="button" value="Submit"></button>');
$("#standard-input-form").html(this.$el.html());
return this;
},

move: function() {
alert("You clicked it");
}
});

$(function(){
var movePalletView = new MovePalletView()
movePalletView.render();
})

</script>
</body>
</html>

最佳答案

如果有任何其他新手在审查这个问题,这是工作代码。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dairy Tracker</title>
<script src="../../external/jquery.js"></script>
<script src="../../external/underscore.js"></script>
<script src="../../external/backbone.js"></script>
<script src="src/MovePallet.js"></script>
</head>
<body>
<form id="standard-input-form"></form>
<script>

var MovePalletView = Backbone.View.extend({
el: '#standard-input-form',
initialize: function () {},

events: {
'submit': 'move'
},

render: function (event) {
this.$el.append('<button type="submit" value="Submit"></button>');
return this;
},

move: function (e) {
e.preventDefault(); //this line keeps the page from refreshing after closing the following alert.
alert("You clicked it");
}
});

$(function(){
var movePalletView = new MovePalletView()
movePalletView.render();
});

</script>

</body>
</html>

关于backbone.js - Backbone JS 按钮单击事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33830214/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com