0

2 つの数値を加算して結果を別のページに表示するコードを書いています。しかし、目的の出力が得られません。

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);
  });
});
4

1 に答える 1

0

.click()use .on()withを使用する代わりにclick and tap:

$('#addbtn').on('click tap', function() {

.on()代わりにもう1つの変更を使用します.delegate()

$(document).on('#calc', 'pageinit', function() { 

ノート:

.on()必要jQuery version 1.7+

于 2013-03-04T08:40:37.377 に答える