简体   繁体   中英

Phonegap app using localstorage function error

I'm trying to use this function with the HTML button (see code below):

function addTestBooks(form) {
  alert("initating addtestbook");
  var formTestBooks = form.addtestbook.value;
  if (formTestBooks == "Add Test Books") {
    var bookNumber = "2";
    var bookTitle = "De Valse Dageraad";
    var BookAuthor = "Jan van Aken";
    var bookGenre = "History";
    var comment = "Leuk boek";
    var addNewKeyValue = bookTitle + "_" + bookAuthor + "_" + bookGenre + "_" + comment;
    window.localStorage.setItem(bookNumber, addNewKeyValue);

    var realtest = window.localStorage.getItem(bookNumber);
    alert("  You added:  " + realtest);
  } else {
    alert("Error executing addTestBooks");
  }
}

HTML Code:

<form id="addnew" name="myform" method="GET">
  <input type="button" class="" name="addtestbook" Value="Add Test Books" onClick="addTestBooks(this.form)">
</form>

When I click on the button I get the error from the else 'section' of the code, Error executing addTestBooks . I'm not sure why this happens because my other localstorage functions are working properly. (Some of them look almost the same even..) I even tried clearing localstorage before I used the function but with no success. (I only show the relevant code here)

Thank you for your time.

var BookAuthor,但稍后要使用bookAuthor,请参见book中的小写b

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM