我正在编写代码以添加两个数字,在另一个页面上显示结果。但我没有得到理想的输出。
addbtn =按钮ID add =结果页面ID calc =起始页面ID ....这是我的代码:
// Bind to 'page init' event for our data page
$(document).delegate('#calc', 'pageinit', function() {
// Do some processing when the button with id 'addbtn' is clicked ( or tapped )
$('#addbtn').click(function() {
// Read the values
var num1 = $("#num1").val(), num2 = $("#num2").val();
var add = parseInt(num1) + parseInt(num2) ;
$add = $('#add');
// Clear the value if value isn't proper
if (add == '0.000' || add == 'Infinity' || add == 'Na N') {
add = '';
}
// Get to the DOM node that has the actual text
while ($add.children().length) {
$add = $add.children().first();
}
// Set it to the calculated value
$("#add").text(add);
});
});
答案 0 :(得分:0)
而是使用.click()
将.on()
与click and tap
一起使用:
$('#addbtn').on('click tap', function() {
另外一项更改使用.on()
代替.delegate()
:
$(document).on('#calc', 'pageinit', function() {
.on()
需要jQuery version 1.7+