Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我需要帮助阅读这段代码来理解它在做什么,这样我就可以把它转换成javascript_Javascript_Jquery_Css_Html - Fatal编程技术网

我需要帮助阅读这段代码来理解它在做什么,这样我就可以把它转换成javascript

我需要帮助阅读这段代码来理解它在做什么,这样我就可以把它转换成javascript,javascript,jquery,css,html,Javascript,Jquery,Css,Html,我想学习JavaScript。我知道jQuery是JavaScript的一个库,但是语法非常不同,我只需要一些帮助来阅读代码,这样我就可以使用JavaScript重新创建它 我正在youtube教程中的一个项目中工作,该项目使用jQuery Mobile将项目添加到WebSQL数据库。在教程中,我正在更新我们输入的项目。代码能够用我们输入的信息填充更新表单。代码工作得很好,但它在jQuery中,如果可能的话,我想将其更改为JavaScript。你能帮我解释一下代码实际在做什么,以及如何将其转换为

我想学习JavaScript。我知道jQuery是JavaScript的一个库,但是语法非常不同,我只需要一些帮助来阅读代码,这样我就可以使用JavaScript重新创建它

我正在youtube教程中的一个项目中工作,该项目使用jQuery Mobile将项目添加到WebSQL数据库。在教程中,我正在更新我们输入的项目。代码能够用我们输入的信息填充更新表单。代码工作得很好,但它在jQuery中,如果可能的话,我想将其更改为JavaScript。你能帮我解释一下代码实际在做什么,以及如何将其转换为JavaScript吗

更新表单的HTML代码

<div data-role="header"> <h1>Update Product</h1> </div> <div data-role="main" class="ui-content"> <form> <div class="ui-field-contain"> <label for="newName" class="ui-hidden-accessible">Name</label> <input type="text" id="newName" data-clear-btn="true" placeholder="New Name"/><br/> <label for="newQuantity" class="ui-hidden-accessible">Quantity</label> <input type="number" name="number" pattern="[0-9}" id="newQuantity" value="" data-clear-btn="true" placeholder="New Quantity"/><br/> <button class="ui-btn ui-icon-plus ui-btn-icon-left" id="btnupdate" onclick="updateProduct()">Update</button> </div> </form> </div> ```` </div> JavaScript Code of populating the form and then updating the changes. ````var currentProduct = { id:-1, name: "", quantity:-1, ````} ````$(document).on('pagebeforeshow', '#updatedialog', function() { $('#newName').val(currentProduct.name); $('#newQuantity').val(currentProduct.quantity); }); function updateProduct() { var newName = $('#newName').val(); var newQuantity = $('#newQuantity').val(); productHandler.updateProduct(currentProduct.id, newName, newQuantity); } 更新产品 名称

更新 ```` 填充表单然后更新更改的JavaScript代码。 ````var currentProduct={ id:-1, 姓名:“, 数量:-1, ````} ````$(文档).on('pagebeforeshow','updatedialog',function(){ $('#newName').val(currentProduct.name); $('#newQuantity').val(currentProduct.quantity); }); 函数updateProduct(){ var newName=$('#newName').val(); var newQuantity=$('#newQuantity').val(); productHandler.updateProduct(currentProduct.id、newName、newQuantity); } databaseHandler.db.transaction( 功能(tx){ tx.executeSql( “更新产品集名称=?,数量=?其中id=?”, [newName,newQuantity,\u id], 函数(tx,results){}, 功能(发送,错误){//todo:向用户显示此消息 console.log(“错误更新产品”+错误消息); } ); } ); }
我想用产品信息填充更新表单,更改表单上的任何信息,并使用JavaScript而不是jQuery更新信息。

每当我需要将jQuery代码更改为JavaScript时,我都会使用此网页:和。您应该拥有将Jquery部分更改为javascript所需的所有信息

最明显的是将“$”替换为document.queryselectoral

例如:

$('#newName').val(currentProduct.name);
替换为:

document.getElementById('newName').value = currentProduct.name;

希望有帮助

以下是jQuery部分:

$(document).on('pagebeforeshow', '#updatedialog', function() {
    $('#newName').val(currentProduct.name);
    $('#newQuantity').val(currentProduct.quantity);
});

function updateProduct() {
    var newName = $('#newName').val();
    var newQuantity = $('#newQuantity').val();
    productHandler.updateProduct(currentProduct.id, newName, newQuantity);
}
下面是如何将它们转换为纯JavaScript:

document.getElementById("updatedialog").addEventListener("pagebeforeshow", function() {
    document.getElementById("newName").value = currentProduct.name;
    document.getElementById("newQuantity").value = currentProduct.name;
});

function updateProduct() {
    var newName = document.getElementById("newName").value
    var newQuantity = document.getElementById("newQuantity").value
    productHandler.updateProduct(currentProduct.id, newName, newQuantity);
}

我昨天看到了那个网站,我需要去详细查看一下。谢谢,这确实有用!我已经测试了document.querySelectorAll方法,但是表单中没有填充信息。你知道为什么它可以完美地与jQuery一起工作,而不能与JavaScript一起工作吗?@ElianaHebrew是的,我在JavaScript中犯了一个错误。更正了。哦,好的,那么jQuery中的$就是JavaScript中的document.getElementById?所以我测试了一下,并使用JavaScript而不是jQuery带走了填充的产品信息。对于JavaScript,我是否需要另一行代码来实现这一点?因此JavaScript代码不应该阻止表单填充产品信息?是的,我理解这就是为什么我说“我知道jQuery是JavaScript的库”我询问的是整个代码,我想知道代码在做什么,这样我才能理解如何将jQuery更改为JS
document.getElementById("updatedialog").addEventListener("pagebeforeshow", function() {
    document.getElementById("newName").value = currentProduct.name;
    document.getElementById("newQuantity").value = currentProduct.name;
});

function updateProduct() {
    var newName = document.getElementById("newName").value
    var newQuantity = document.getElementById("newQuantity").value
    productHandler.updateProduct(currentProduct.id, newName, newQuantity);
}