当前位置: 首页 > 图文教程 > 网络编程 > Javascript > Js 本页面传值实现代码

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 Js 本页面传值实现代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 304 ::
收藏到网摘: n/a

记得以前在学校的时候,例如要修改信息,需要要修改的部分的值显示出来,都是先把数据传到后台,然后再在前台显示的,想想真够笨的,这个可以在客户端就实现的,何必要传到后台呢 环境 : rails 下
例如:
image
我点击修改后显示成这样:
image
关键实现过程:
1,列表部分,即第一副图,蓝色部分即实现了传值
复制代码 代码如下:

<% i=0 %>
<% if @group_page %>
<% for group in @group_page %>
<% i+=1 %>
<tr <%= i%2==0 ? "class='bg'" : '' %> >
<td class="first style1"><%= group.id.to_s %></td>
<td><%= group.group_name==nil ? '': group.group_name.to_s %></td>
<td><%= group.display_order==nil ? '': group.display_order.to_s %></td>
<td><%= group.update_dt.strftime("%Y-%m-%d") %></td>
<td><%= group.status.to_s == '0' ? '正常': "禁用" %></td>
<td><%= group.group_comment==nil ? '': group.group_comment.to_s %></td>
<td><%= link_to image_tag('/images/cs/edit-icon.gif'),{},{:onclick =>"show_div('" + group.id.to_s + "','" + group.group_name.to_s + "','" + group.display_order.to_s + "','" + group.status.to_s + "','" + group.group_comment.to_s + "');return false;" } %></td>
<td><%= link_to image_tag('/images/cs/hr.gif'),{:action=>'deletegroup',:id=>group.id.to_s},{:confirm=>'确定要删除吗?'} %></td>
</tr>
<% end %>
<% end %>

2,js函数部分
复制代码 代码如下:

<script>
function show_div(object1,object2,object3,object4,object5)
{
document.getElementById("original_group").style.display = "none";
document.getElementById("modify_group").style.display="";
document.getElementById("group_id").value =object1;
document.getElementById("modify_name").value =object2;
document.getElementById("modify_order").value =object3;
if ( object4 == "0"){
document.getElementById('modify_status').selectedIndex=0;
}
if( object4 == "1"){
document.getElementById('modify_status').selectedIndex=1;
}
document.getElementById("modify_comment").value =object5;
}
</script>

这样你就实现了客户端利用js传值...............