通过JavaScript将选择选项从一个HTML页面传递到另一个HTML页面...... [英] Passing select options via JavaScript from one HTML page to another...

查看:85
本文介绍了通过JavaScript将选择选项从一个HTML页面传递到另一个HTML页面......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在尝试从

正确传递我的选择(课程)以下网址: http://www.dslextreme.com/users/kevi...lectBoxes.html


我很难让课程通过正确的选项

值,然后显示在以下网址:
http://www.dslextreme.com/users/kevi...ctResults.html


我正在通过国家/地区,产品和课程。前两个显示

,因为它们应该在后续页面上,但是这些课程保留了我的循环

变量而不是我想要的值。另外,我注意到该变量没有从产品中分离出来。


我欢迎任何人查看每个代码以查看我能做什么to

更正的东西。


非常感谢,


凯文

解决方案

在文章< 63 ************************** @ posting.google.com> ,
ma*********@go.com 说......

您好,

我正在尝试从以下网址正确传递我的选择(课程): http://www.dslextreme.com/users/kevi...lectBoxes.html

我很难让课程传递正确的选项
值,然后显示在以下网址:
http://www.dslextreme.com/users/kevi...ctResults.html

我正在通过国家/地区,产品和课程。前两个显示
应该在后续页面,但课程保留我的循环变量而不是我想要的值。另外,我注意到变量没有从产品中分离出来。




这可能会有所帮助:
http://hyweljenkins.co.uk/programmin...avaScript&id=5


-

Hywel我不吃乳蛋饼
http://hyweljenkins.co.uk/
http://hyweljenkins.co.uk/mfaq.php


Kevin Lyons写道:

您好,

我正在尝试从以下网址正确传递我的选择(课程): http://www.dslextreme.com/users/kevi...lectBoxes.html
值,然后显示在以下URL:
http://www.dslextreme.com/users/kevi...ctResults.html

我正在通过国家/地区,产品和课程。前两个显示
应该在后续页面,但课程保留我的循环变量而不是我想要的值。另外,我注意到变量没有从产品中分离出来。

我欢迎任何人查看每个代码,看看我能做些什么来更正。

非常感谢,

Kevin




你现在正在为你的代码使用32个数组变量,我认为

你只需要5个阵列,那就是它。我不明白你做了什么

你的8

var Top_Database = new Array();

var Top_Development = new Array();

var Top_Server = new Array();

var Top_Applications = new Array();


var Blank_Database = new Array( );

var Blank_Development = new Array();

var Blank_Server = new Array();

var Blank_Applications = new Array();

数组。你声明这8个数组,但你从来没有定义它们,也没有使用

它们。如果你的脚本已经运行(处理一个很多变量,数组)需要来自用户的系统资源的大量cpu和RAM,那么请避免这种情况。 br />

你不觉得你的剧本中有很多重复的元素

代码(其他24个数组)?每当有元素重复

时,循环可以优化代码并使其更紧凑,

高效。

我是非常相信你可以用5个阵列替换这24个阵列

它们可以/将动态组合起来生成值

你的< select name =" courses" ...>


绝对避免代码中的eval()调用;从编程的角度来看,众所周知这是次要的,缓慢的,错误的,坏的或完全错误的。

另外,尽量避免使用document.write()调用。 99.9%这样的调用

可以被DOM属性和方法所取代,这些属性和方法为页面提供了更多的b / b
DOM和脚本功能。


引用所有属性值无处不在:只需通过

这样做就可以避免错误,并且有助于加快解析速度。例如。在您的代码中:

< td width = 25%>将被读取并解析为一个请求宽度为
25像素的td,而不是其父容器的25%。

http://www.htmlhelp.org/faq/html/basics.html#quotes

"默认情况下,SGML要求所有属性值使用

分隔双引号(...)
http://www.w3.org/TR/html4/intro/sgm .. .tml#attributes

为什么属性值应始终用HTML引用
http://www.cs.tut.fi/~jkorpela/qattr.html


if( event.srcElement.tagName ==" INPUT")

event.srcElement.className = color;

避免仅编码MSIE;您的页面完全符合W3C web

标准,并且在符合W3C Web标准的浏览器中完美运行。

srcElement不是DOM 2事件的可识别属性(目标是) ;

事件不是W3C DOM 2事件中的可识别对象。只需一点

的跨浏览器代码,您就可以在这里至少使用25个其他的b $ b浏览器。


了解属性的默认值可以减少页面的标记汤。

< td>的默认水平对齐方式细胞留下了。所以,

< td align =" left" ...>是99%的时间是无用的,毫无意义的b $ b声明。知道哪些css属性是继承的同样的事情

以及浏览器中的默认值:知道经常意味着你

甚至不必声明它们。这种好的和明智的编码技术有助于使页面更加高效,快速,健壮,避免问题或崩溃,使页面更具互操作性等。


为您的html文件使用doctype声明并验证您的网页。

这样做符合您的最佳利益,以便您的页面呈现

始终符合W3C Web标准兼容的浏览器,并且它可以在不同的媒体,操作系统,网络感知设备等上进行互操作。


W3C验证器
http://validator.w3.org/


使用Doctype声明激活正确的布局模式
http://www.hut.fi/u/hsivonen/doctype.html


有效doctype列表
http://www.w3.or g / QA / 2002/04 / valid-dtd-list.html


我的网站是标准的!你的呢? W3C质量保证
http:// www。 w3.org/QA/2002/04/Web-质量


为什么我们不能帮助你
http://diveintomark.org/archives/200..._wont_help_you


DU

-

Javascript和浏览器错误:
http://www10.brinkster.com/doctorunclear/

- Netscape 7.x用户的资源,帮助和提示作曲家

- 在Netscape 7.x中弹出窗口,音乐(音频/ midi)的互动演示
http://www10.brinkster.com/doctorunc...e7Section.html


ma * ********@go.com (Kevin Lyons)写道:

我很难让课程通过正确的选项
值,然后显示在以下URL:
http: //www.dslextreme.com/users/kevi...ctResults.html




我可以看到一些问题。

1:< SCRIPT LANGUAGE =" JavaScript">

在HTML 4中,脚本标记需要type属性:

< script type =" text / javascript">


2:onload =" acceptParams(this.location.search)"

位置对象是不是body元素的属性(至少在所有


3:开始=停止+ 2 +产品。长度

这并不像你想象的那样联想到。添加括号:

开始=停止+ 2 +(" products" .length)

下一个开始时相同。


4:Stop = Invar.length

因此产品一直持续到字符串结束。这就是为什么它不会分裂的原因。你不能拆分它。


4:你假设参数按顺序传递:country,

产品,课程。 HTML或HTTP定义中没有任何内容

要求使用GET方法传递的表单元素与页面上的

顺序相同。


我会做什么:

---

函数acceptParams(paramStr){

var params = new Object();

var pairs = paramStr.substring(1).split("&");

for(var i in pairs) {

var pair = pairs [i] .split(" =");

params [pair [0]] = unescape(pair [1] .replace (/ \ + / g,""));

}

document.write(" Countries =" + params.Countries +"< ; br>");

document.write(" Products =" + params.products +"< br>");

文件。写(Courses =" + params.courses +"< br>);

}

---

(这不是对传递的表单元素的完全一般解析。它

不处理多个元素具有相同名称的ts(如复选框

或radiogroups),并且它不会处理type =" image" (

发送" name.x = 42& name.y = 27"或类似)。


/ L

-

Lasse Reichstein Nielsen - lr*@hotpop.com

Art D ''HTML:< URL:http://www.infimum.dk/HTML/randomArtSplit.html>

''没有判断的信仰只会降低精神神圣。''


Hello,

I am trying to get my select options (courses) passed correctly from
the following URL: http://www.dslextreme.com/users/kevi...lectBoxes.html

I am having difficulty getting the courses to pass the correct option
value and then be displayed at the following URL:
http://www.dslextreme.com/users/kevi...ctResults.html

I am passing countries, products, and courses. The first two display
as they should on the subsequent page, but the courses retains my loop
variable rather than the value as I would like. Additionally, I
notice that the variable is not being split from the products.

I welcome anyone to review the code from each to see what I can do to
correct things.

Thanks much,

Kevin

解决方案

In article <63**************************@posting.google.com >,
ma*********@go.com says...

Hello,

I am trying to get my select options (courses) passed correctly from
the following URL: http://www.dslextreme.com/users/kevi...lectBoxes.html

I am having difficulty getting the courses to pass the correct option
value and then be displayed at the following URL:
http://www.dslextreme.com/users/kevi...ctResults.html

I am passing countries, products, and courses. The first two display
as they should on the subsequent page, but the courses retains my loop
variable rather than the value as I would like. Additionally, I
notice that the variable is not being split from the products.



This may help:
http://hyweljenkins.co.uk/programmin...avaScript&id=5

--
Hywel I do not eat quiche
http://hyweljenkins.co.uk/
http://hyweljenkins.co.uk/mfaq.php


Kevin Lyons wrote:

Hello,

I am trying to get my select options (courses) passed correctly from
the following URL: http://www.dslextreme.com/users/kevi...lectBoxes.html

I am having difficulty getting the courses to pass the correct option
value and then be displayed at the following URL:
http://www.dslextreme.com/users/kevi...ctResults.html

I am passing countries, products, and courses. The first two display
as they should on the subsequent page, but the courses retains my loop
variable rather than the value as I would like. Additionally, I
notice that the variable is not being split from the products.

I welcome anyone to review the code from each to see what I can do to
correct things.

Thanks much,

Kevin



You''re using 32 array variables for your code when right now, I think
you only need 5 arrays and that''s it. I do not understand what you do
with your 8
var Top_Database = new Array();
var Top_Development = new Array();
var Top_Server = new Array();
var Top_Applications = new Array();

var Blank_Database = new Array();
var Blank_Development = new Array();
var Blank_Server = new Array();
var Blank_Applications = new Array();
arrays. You declare these 8 arrays but you never define them nor use
them. Avoid this furthermore if your script functions already (handle a
lot of variables, arrays) demand a lot of cpu and RAM from the user''s
system resources.

Don''t you see that there is a lot of repetitive elements in your script
code (24 other arrays)? Everytime there is elements repeating
themselves, then a loop can optimize the code and make it more compact,
efficient.
I''m pretty much convinced you can replace these 24 arrays by 5 arrays
which can/will combine themselves dynamically to generate the values in
your <select name="courses" ...>

Absolutely avoid eval() calls in your code; this is widely known to be
inferior, slow, buggy, bad or simply wrong from a programming perspective.
Also, avoid as much as possible document.write() calls. 99.9% such calls
can be replaced by DOM attributes and methods which are giving far more
DOM and script powers to a page.

Quote all your attribute values everywhere: you avoid errors just by
doing so and you help speed up a bit parsing. E.g. in your code:
<td width=25%> will be read and parsed as a td which requested width is
25 pixels, not 25% of its parent container.

http://www.htmlhelp.org/faq/html/basics.html#quotes
"By default, SGML requires that all attribute values be delimited using
either double quotation marks (...)"
http://www.w3.org/TR/html4/intro/sgm...tml#attributes
Why attribute values should always be quoted in HTML
http://www.cs.tut.fi/~jkorpela/qattr.html

if (event.srcElement.tagName == "INPUT")
event.srcElement.className = color;
Avoid coding for MSIE only; your page can comply entirely with W3C web
standards and work flawlessly in W3C web standards compliant browsers.
srcElement is not a recognized attribute of the DOM 2 Event (target is);
event is not an recognized object in W3C DOM 2 Events. With just a bit
of cross-browser code, you can make your page work in at least 25 other
browsers here.

Knowing the default values of attributes can reduce tag soup of a page.
The default horizontal alignment of <td> cells is left. So,
<td align="left" ...> is 99% of the time an useless, pointless
declaration. Same thing with knowing which css properties are inherited
and what are the default values in browsers: knowing so often means you
don''t even have to declare them. Good and wise coding techniques of this
sort help make a page far more efficient, fast, robust, avoiding
problems or crashes, makes a page more interoperable, etc..

Use a doctype declaration for your html file and validate your webpage.
Doing so is in your best interests so that your page renders
consistently on W3C web standards compliant browsers and that it
interoperates on different media, os, web-aware devices, etc..

W3C validator
http://validator.w3.org/

Activating the Right Layout Mode Using the Doctype Declaration
http://www.hut.fi/u/hsivonen/doctype.html

List of valid doctype
http://www.w3.org/QA/2002/04/valid-dtd-list.html

My Web site is standard! And yours? by W3C Quality Assurance
http://www.w3.org/QA/2002/04/Web-Quality

Why we won''t help you
http://diveintomark.org/archives/200..._wont_help_you

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html


ma*********@go.com (Kevin Lyons) writes:

I am having difficulty getting the courses to pass the correct option
value and then be displayed at the following URL:
http://www.dslextreme.com/users/kevi...ctResults.html



I can see some problems.

1: <SCRIPT LANGUAGE="JavaScript">
In HTML 4, the type attribute is required on script tags:
<script type="text/javascript">

2: onload="acceptParams(this.location.search)"
The location object is not a property of the body element (not in all
browsers, at least), so drop "this.".

3: Start = Stop+2+"products".length
This doesn''t associate as you thinkt it does. Add parentheses:
Start = Stop+2+("products".length)
Same for the next Start.

4: Stop = Invar.length
So the products go on until the end of the string. That''s the reason it''s
not split. You don''t split it.

4: You assume that the parameters are passed in the order: country,
products, courses. There is nothing in the HTML or HTTP definitions that
require a form''s elements passed with the GET method to be in the same
order as on the page.

What I would do:
---
function acceptParams(paramStr) {
var params = new Object();
var pairs = paramStr.substring(1).split("&");
for (var i in pairs) {
var pair = pairs[i].split("=");
params[pair[0]] = unescape(pair[1].replace(/\+/g," "));
}
document.write("Countries = " + params.Countries + "<br>");
document.write("Products = " + params.products + "<br>");
document.write("Courses = " + params.courses + "<br>");
}
---
(This is not a completely general parsing of passed form elements. It
doesn''t handle multiple elements with the same name (like checkboxes
or radiogroups), and it doesn''t handle input with type="image" (which
sends "name.x=42&name.y=27" or similar).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D''HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
''Faith without judgement merely degrades the spirit divine.''


这篇关于通过JavaScript将选择选项从一个HTML页面传递到另一个HTML页面......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆