| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 741 人关注过本帖
标题:[求助]请教一个JavaScript问题
只看楼主 加入收藏
笑海
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:4934
专家分:25
注 册:2007-4-29
结帖率:0
收藏
 问题点数:0 回复次数:2 
[求助]请教一个JavaScript问题
请问我这样才能得到加进去的商品的值

<html>
<head>
<title>dyment.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<script language="javascript">
function addsort(){
var name = document.getElementById("name").value;
if(name==""){
return;
}
var row = document.createElement("tr");
row.setAttribute("id",name);
var cell = document.createElement("td");
cell.appendChild(document.createTextNode(name));
row.appendChild(cell);

var tt = document.createElement("input");
tt.setAttribute("type","button");
tt.setAttribute("value","修改");
tt.onclick = function (){rework(name);};
cell = document.createElement("td");
cell.appendChild(tt);
row.appendChild(cell);

document.getElementById("sortList").appendChild(row);
document.getElementById("name").value="";
}
function rework(id){
if(id!=null){
var df = document.getElementById(id);

window.alert("怎样得到品牌名称");/**8我怎样才能得到加进去的商品的值****/

}}
</script>
<body>
增加商品:<input id="name" type="text">
<input type="button" value="确定" onclick="addsort()">
<table border="1" width="400">
<tr>
<td height="20" valign="top" align="center">
品牌名称:
</td>
<td id="pos_2" height="20">
修改
</td>
</tr>
<tbody id="sortList"></tbody>
</table>
</body>
</html>
搜索更多相关主题的帖子: JavaScript name var document 
2007-05-02 19:47
编程之星
Rank: 5Rank: 5
等 级:职业侠客
威 望:2
帖 子:285
专家分:391
注 册:2007-4-10
收藏
得分:0 

为了帮你解决这个问题,可花了我不少时间!(感谢我吧,嘿嘿)
为了解决一些中文显示的问题,你首先要重新设置这个东西:
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
重新设置好后如下:
<meta http-equiv="content-type" content="text/html; charset=GB2312">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
其实你的问题也不难解决,只要采用DOM就能解决问题.
下面给出完整的源于代码(注意蓝色的部分代码):

<html>
<head>
<title>dyment.html</title>
<meta http-equiv="content-type" content="text/html; charset=GB2312">
</head>
<script language="javascript">
function addsort(){
var name = document.getElementById("name").value;
if(name==""){
return;
}
var row = document.createElement("tr");
row.setAttribute("id",name);
var cell = document.createElement("td");
cell.appendChild(document.createTextNode(name));
row.appendChild(cell);

var tt = document.createElement("input");
tt.setAttribute("type","button");
tt.setAttribute("value","修改");
tt.onclick = function (){rework(name);};
cell = document.createElement("td");
cell.appendChild(tt);
row.appendChild(cell);

document.getElementById("sortList").appendChild(row);
document.getElementById("name").value="";
}
function rework(id){
if(id!=null){
var df = document.getElementById(id);

window.alert("怎样得到品牌名称");/**8我怎样才能得到加进去的商品的值****/

}}
function getProductValue(me)
{
me=parseInt(me)-1;
alert(document.getElementById("sortList").childNodes.item(me).firstChild.innerText);
}

</script>
<body>
增加商品:<input id="name" type="text">
<input type="button" value="确定" onclick="addsort()">
<table border="1" width="400">
<tr>
<td height="20" valign="top" align="center">
品牌名称:
</td>
<td id="pos_2" height="20">
修改
</td>
</tr>
<tbody id="sortList"></tbody>
</table>
<br>
<br>
(请先添加商品)取得 第 <input id="index" size=2> 项商品的值(填入数字,例如:1)<button onclick="getProductValue(index.value)">确定</button>

</body>
</html>

[此贴子已经被作者于2007-5-3 14:21:04编辑过]


怎么越学就觉得自己越笨
2007-05-03 14:16
笑海
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:4934
专家分:25
注 册:2007-4-29
收藏
得分:0 
感激感激 谢谢 谢谢 那我先拿过去试试拉



兔子不吃窝边草
2007-05-03 17:32
快速回复:[求助]请教一个JavaScript问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026045 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved