English 中文(简体)
在 div 中选择元素并发送数据到数据库
原标题:Selecting elements in a div and send data to database

更具体地说,就是由用户的“Twitter”的“Twitter”追随者配置图象构成的“启动陷阱”模型。

这是表格:http://d.pr/i/ZJMk

这是能起作用的代码。

<div class="modal-body">  

  <?php

    $follower_url = "http://api.twitter.com/1/statuses/followers/Mozammil_K.xml";

    $twFriends = curl_init();

    curl_setopt($twFriends, CURLOPT_URL, $follower_url);
    curl_setopt($twFriends, CURLOPT_RETURNTRANSFER, TRUE);
    $twiFriends = curl_exec($twFriends);
    $response = new SimpleXMLElement($twiFriends);

    foreach($response->user as $friends){ 
        $thumb = $friends->profile_image_url;
        $url = $friends->screen_name;
        $name = $friends->name;

    ?>



    <a title="<?php echo $url;?>" href="#"><img class="photo-img" src="<?php echo $thumb?>" border="2" alt="" width="40" onClick="highlight(this)" /></a>
    <?php

    } 

  ?>



</div>

我想给用户一个选项, 点击照片并选择元素。 他们也可以再次点击照片并取消其选择 。 这通过下面的 Javascript 实现了 。

<script>

   function highlight(elem) {

    if(elem.style.border ==  2px solid blue ) {

        elem.style.border =   ;
    }
    else{

        elem.style.border =  2px solid blue ;

    }

    }

</script>

点击创建按钮时, 窗体应该获得突出显示元素的标题, 并将元素标题发送到数据库 。 除了将元素保存到一个阵列并通过 JSON 发送数据之外, 我找不到任何方法做到这一点 。 我不太熟悉 JSON 。 是否还有其他方法( 简单)? 也许 JQuery?

请注意

问题回答

I think this would be the solution for your problem, I added these three attribute to <a class= a-img > tag

      "rel=<?echo $thumb?>" 
      "id=<?echo $name?>" 
      "title=<? echo $url;?>" //these will be the diffrent attr to be send on the database

and these 3 attribute must be pass to a hidden input if you click the "a.a-img" must add 3 hidden fields:

      <input type="hidden" id="sname"/>
      <input type="hidden" id="fname"/>
      <input type="hidden" id="thumb"/>

     <a title="<?php echo $url;? class= a-img >" href="#">
     <img class="photo-img" src="<?php echo  $thumb?>" border="2" alt="" width="40"   
     onClick="highlight(this)" /></a>
     $(document).ready(function(){

      $("#create").click(function(){
      //get the value of the 3 hidden fields 
      var sname =  $("#sname").val(sname);
      var fname = $("#fname").val(fname);
      var thumb = $("#thumb").val(thumb);

         $.ajax({
             type:"POST",
             url:"//your savetodb.php"
             data:{ sname :sname,  fname :fname,  thumb :thumb},
             success: function(data){
                        //do success message
                     }
         });

      });

      $("a.a-img").click(function(){
        var sname = $(this).attt( title );
        var fname = $(this).attr( id );
        var thumb = $(this).attr( rel );
               //these 3 attrbute will pass to a hidden input
                $("#sname").val(sname);
                $("#fname").val(fname);
                $("#thumb").val(thumb);
      });
 });

希望这能帮到你





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签