Jump to content
php.lv forumi
  • 0

Atzīmēt <tr> rindiņu...


reiniger

Question

Sveiki.

 

Ir "nelielas" Javascript zināšanu trūkums.

 

Ir sekojoša tabula un uzpiežot uz attiecīgas rindiņas šī rindiņa tiek iezīmēta(background nomainas) un tiek piefiksēts rindiņas ID lai talak nospiežot Submit attiecīgie ierakstus pec ID numura varētu izdzēst.

 

<script language="JavaScript">
function actionClick(Aval)
{
   document.myform.formVar.value=Aval
}

</script>

<form method="post" name="myform">
<table>
<tr>
 <td>ID</td>
 <td>tilte</td>
 <td>tekst</td>
</tr>
<tr style="background:red" onclick="actionClick(1)">
 <td>1</td>
 <td>test</td>
 <td>teksts</td>
</tr>
<tr style="background:red" onclick="actionClick(2)">
 <td>2</td>
 <td>test2</td>
 <td>teksts2</td>
</tr>
</table>
<input type="text" name="formVar" value="">
<input type="submit" value="dzest">
</form>

Tas iesakuma ideja!

 

Mana doma ir vertibu saglabat viena input formVar velak nomainot uz hidden. bet ka labak panākt to ka ieķeksē varākus tad nosūtas ta ka masīvs bet ir iespēja arī kādu no atķeksētajiem izņemt arā no saraksta.

 

Kā labāk uztaisīt?

Edited by reiniger
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Ja vairāk jādarbojas ar js, tad ir vērt izmantot jquery:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
var sel=0;
$(function(){
 $('#mytable tr').click(function(){
   if (sel) sel.removeClass('sel');
   sel=$(this);
   $(this).addClass('sel');
 });
 $('#btn_del').click(function(){
   alert(sel.attr('rowid'));
 });
});
</script>
<style>
#mytable tr{
 background:#dfd;
}
#mytable tr.sel{
 background:#fdd;
}
</style>
</head>
<body>
 <table id="mytable">
   <tr rowid="1">
     <td>lol</td>
     <td>lol</td>
     <td>lol</td>
   </tr>
   <tr rowid="2">
     <td>lol</td>
     <td>lol</td>
     <td>lol</td>
   </tr>
   <tr rowid="3">
     <td>lol</td>
     <td>lol</td>
     <td>lol</td>
   </tr>
 </table>
 <button id="btn_del">delete</button>
</body>
</html>

Edited by codez
Link to comment
Share on other sites

  • 0

šādi:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(function(){
 $('#mytable tr').click(function(){
   $(this).toggleClass('sel');
 });
 $('#btn_del').click(function(){
   var s='';
   $('#mytable tr.sel').each(function(){
     s+=(s!=''?',':'')+$(this).attr('rowid');
   });
   alert(s);
 });
});
</script>
<style>
#mytable tr{
 background:#dfd;
}
#mytable tr.sel{
 background:#fdd;
}
</style>
</head>
<body>
 <table id="mytable">
   <tr rowid="1">
     <td>lol</td>
     <td>lol</td>
     <td>lol</td>
   </tr>
   <tr rowid="2">
     <td>lol</td>
     <td>lol</td>
     <td>lol</td>
   </tr>
   <tr rowid="3">
     <td>lol</td>
     <td>lol</td>
     <td>lol</td>
   </tr>
 </table>
 <button id="btn_del">delete</button>
</body>
</html>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...