将值传递给javascript-document.getElementByID [英] pass value to javascript-document.getElementByID

查看:92
本文介绍了将值传递给javascript-document.getElementByID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQTouch作为主题的移动Web应用程序.我在尝试将超链接参数/值传递给javascript函数时遇到问题.链接是从Websql查询生成的列表的一部分:

这就是列表-在主HTML的div标签上,仅将行ID设置为"xres"作为ID很好地显示

Im working on a mobile web app using jQTouch for the theme. Im having an issue trying to pass a hyperlink parameter/value to a javascript function. The link is part of a list that is generated from a websql query:

THIS IS THE LIST - which nicely display with only the ID of a row set to "xres" as an id on a div tag in the main HTML

function dspList() {
db.transaction(function (tx) {
  tx.executeSql('SELECT * FROM UBP', [], function (tx, results) {
   var len = results.rows.length, i;
   for (i = 0; i < len; i++){
     xres = "<li class='arrow'><a href='#userdisplay'  önclick='dspUser()'>" + results.rows.item(i).uaid + "</a></li>";
     document.querySelector('#xres').innerHTML +=  xres;
   }
 }, null);
});
}



这是显示列表的HTML标签:



THIS IS THE HTML TAG THAT DISPLAYS THE LIST:

<div id="myinfo">
    <div class="toolbar">
        <h1>My Info</h1>
        <a class="button back" href="#home"  önclick="goRefresh(0)">Back</a>
    </div>
    <ul class="edgetoedge">
    <div id="xres"></div>
    </ul>
</div>



单击列表中的一项时,即:
3459
4436
2255

..it运行以下javascript函数:



When clicking one of the items on the list, ie:
3459
4436
2255

..it runs this javascript function:

function dspUser() {
var xuaid = document.getElementById("xres");
db.transaction(function (tx) {
  tx.executeSql('SELECT * FROM UBP WHERE (uaid = ?) ', [xuaid], function (tx, results) {
     {
     xres1 = results.rows.item(0).uaid + " - " + results.rows.item(0).user;
     document.querySelector('#xres1').innerHTML +=  xres1;
     }
 }, null);
});
}



..并显示以下HTML:



..and displays with this HTML:

<div id="userdisplay">

    <div class="toolbar">
        <h1>User Information</h1>
        <a class="button back" href="#myinfo">Back</a>
    </div>

    <div>
        <ul class="plain12">
        <span class="fontleft18"><div id="xres1">Results here..</div></span>
        </ul>
    </div>

</div>



我是javascript的新手,但真的很想学习和构建一些Web应用程序.谁能帮我找出为什么我不能将id = xres的值传递给函数dspUser()以便仅查询特定id/行的websql吗?我是否对document.getElementById使用正确的功能?这甚至是从也由websql查询生成的列表显示中查询websql的正确方法/过程吗?

任何帮助将不胜感激.

Octavious



Im very new at javascript, but would really like to learn and build some web apps. Can anyone help me figure out why I cant pass the value of the id=xres to the function dspUser() so that I can query the websql for just that particular id/row? Am I using the correct function with the document.getElementById? Is this even the correct way/process to query the websql from a list display that was also generated by a websql query?

Any help would be greatly appreciated.

Octavious

推荐答案

嗨-

我认为您必须创建一个循环,因为您的查询返回了多个数据.
函数getElementById是正确的,但是它将仅返回元素集合,在您的情况下,该集合是
Hi--

i think you have to create a loop because your query returns more than one data.
the function getElementById is correct however it will just return only the element collection which in your case is all the element of the
标记的所有元素.

让您获取标记内每个元素的值:

tag.

for you to get the value of each elements inside the tag:

var xuaid = document.getElementById("xres");

for var x = 0; x < myObj.length; x++){

     alert (xuaid.childNodes[x].value);

}



..类似的东西..这是一个有用的链接:

dottoro



..something like that.. and here''s a useful link:

dottoro


这篇关于将值传递给javascript-document.getElementByID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆