-1

I am new to HTML5. I would like to build a website using HTML5 that I can use in both Android and iPhone. I spent a couple of days to get a solution, but failed. Below is my scenario:

  1. MySQLdatabase has a table (userinfo) which stores user information, e.g. name, age, sex, occupation, hobby, address, etc.
  2. I have an HTML5 design (category.html) where 3 options (age<5,age>5 and age<20,age>20) exist as list with anchor tag.
  3. If I touch age<5, then it will show a list of all users with name and sex whose age is less than 5 in list.html. Next I will touch a name from this list and it will show details of this user in details.html

The query is simple: select name,sex from userinfo where age<5/age>20 etc.

I am using PHP to connect to the database. When I use a button to assign an action (GET/POST method in PHP) in a form, it is easy for me, but here it is not a button. It is a list with an anchor link. How can I do it? The above scenario is for both Android and iPhone.

4

2 に答える 2

1

POST データを送信するには、データをサーバーに送信する必要があります。ハイパーリンクだけではこれを行うことはできませんが、JS マジックを少し使えば、これを簡単に実現できます。

jQuery などを使用している場合は、クリック イベントをキャプチャできます。クリック イベントに基づいてリンクからデータを収集し、$.post/$.ajax 経由でサーバーに送信します。

HTML:

<a href="javascript:void(0);" class="age-less-then-five">age<5</a>

Javascript:

$('a.classname').click(function(){
            var that = $(this), value = that.text().trim(); 
            //you can optionally store a value in the classname, or ID which is what I would do.. in this scenario.. I think XD

            $.post('yoururl.com/phpscript.php',{postName: value}, function(data){
                //load whatever data you want, or redirect to list.html now that you've gathered desired data
            }
        });

上記の答えを明確にするために、 var that = $(this); クリックされたリンクを参照します。したがって、次のようにしてアンカーからクラス名を取得できます。 (). ここでトリムします。これは実際にはこれを行う最善の方法ではありません..しかし、これはそれを行う 1 つの方法です。リンクを使用してサーバーへの任意の種類の投稿を実行する場合、ID が一意の値またはクラス名を保持している場合は通常、ID を使用します。

于 2012-08-11T06:44:30.627 に答える
1

これは私がすることです: 次のように、ボタンをリンクとして表示します:

.link {
    background: none;
    border: none;
    text-decoration: underline;
    color: blue;
    cursor: pointer
}

linkあとは、リンクとして表示したいすべてのボタンにクラスを割り当てるだけです。

于 2012-08-11T06:31:29.307 に答える