在我将其与$("#id")一起使用后,相同的代码就不起作用了.append.代码看起来像没有加载jq

same code not work after i use it with $("#id").append.the code look like the code that not load jquery and jquery moblie

本文关键字:代码 quot 不起作用 jq append 看起来 加载 #id 一起      更新时间:2023-09-26

我使用了这个html代码,它运行得很好。按钮可以点击和改变一个页面,就像我想。

<table id="myTable" style="background-color: #FAF0BA; width: 95%">
   <thead>
      <tr align="center"  style="background-color: #009972; color: #FAF0BA;">
         <td>#id</td>
         <td>name</td>
         <td>info</td>
      </tr>
   </thead>
   <tr align="center" style="background-color: #8AABBA; color: #FAF0BA;" >
      <td>1</td>
      <td>jui co.</td>
      <td><button style="background-color: #FAF0BA; color:#00CCA5;" data-role ="button" data-mini="true" data-inline="true" data-icon ="info" class="info" value="1">info</button></td>
   </tr>
</table>

现在我想将id和name添加到sqlite数据库中。在我使用$('#my_data'(.empty((.append((添加i wan以显示在div id="my_data"下。我的append代码与我上面使用的代码相同。

function renderList(tx, results) {
    var htmlstring = '<table id="myTable" style="background-color: #FAF0BA; width: 95%">'n';
    htmlstring += "<thead>'n";
    htmlstring += "<div id='"current_login'" style='"background-color: #009972;'"></div>'n";
    htmlstring += "<tr align='"center'"  style='"background-color: #009972; color: #FAF0BA;'">'n";
    htmlstring += "<td>#id</td>'n";
    htmlstring += "<td>name</td>'n";
    htmlstring += "<td>info</td>'n";
    htmlstring += "</tr>'n";
    htmlstring +="</thead>'n";
    var len = results.rows.length;
    for (var i = 0; i < len; i++) {
        htmlstring += "<tr align='"center'" style='"background-color: #8AABBA; color: #FAF0BA;'" >";
        htmlstring += "<td>" + results.rows.item(i).cid + "</td>";
        htmlstring += "<td>" + results.rows.item(i).name + "</td>";
        htmlstring += "<td><button style='"background-color: #FAF0BA; color:#00CCA5;'" data-role ='"button'" data-mini='"true'" data-inline='"true'" data-icon ='"info'" class='"info'" value='"" + results.rows.item(i).cid + "'">info</button></td>";
        htmlstring += "</tr>";
    }
      htmlstring +="</table>";
      $('#my_data').empty().append(htmlstring);
}

它显示在屏幕上,但看起来像是当我没有导入jquery和jquery mobile时(我做了,它在第一个代码中运行良好(,然后点击按钮,它就不工作了。看起来它没有加载jquery和jquery mobile。当我删除jquery和jquery移动导入并运行第一个代码时,它看起来是一样的。如何使其发挥作用?

ps.my点击代码。

$(document).ready(function () {
    $(".info").on("tap",
            function () {
                document.location.href = "./customer_info.html" + "#id=" + $(this).attr("value") + "&name=" + uid;
            });
});

--------------------------更新1------------------------

我尝试了下面的代码,但它仍然不起作用

$(document).ready(function () {
    $('#my_data').on("tap",".info",
            function () {
                document.location.href = "./customer_info.html" + "#id=" + $(this).attr("value") + "&name=" + uid;
            });
});

要获得jQM样式,必须告诉jQM在将小部件附加到页面后增强它们。对于jQM 1.3.x:

$('#my_data').empty().append(htmlstring).trigger("create");

对于jQM 1.4.x,您可以使用

$('#my_data').empty().append(htmlstring).enhanceWithin("");

对于单击处理程序,uid来自哪里?如果它有空格和特殊字符,则必须对其进行url编码以包含在链接地址encodeURIComponent(uid)中。若要传递查询字符串,请使用"?"而不是.html.后面的"#">

$('#my_data').on("tap",".info", function () {
    var uid = "jui. co";
    var url = "./customer_info.html" + "?id=" + $(this).prop("value") + "&name=" + encodeURIComponent(uid);
    alert(url);
    location.href = url;
});

演示

function () {
    document.location.href = "./customer_info.html" + "#id=" + $(this).attr("value") + "&name=" + uid;
});

尝试用?id 替换#id