通用innerHTML功能和其他小问题...... [英] Generic innerHTML functionality and other minor questions...

查看:48
本文介绍了通用innerHTML功能和其他小问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

欢迎

我已经阅读了关于通用

DynWrite的常见问题解答,但我也意识到这只是使用了
$的innerHTML功能b $ b HTML对象。

(1)是否存在与innerHTML属性非常类似的DOM函数

例如。 (我的猜测)setInnerNodeAsText或sth ......?


我想编写的函数将动态更新我的一些

选择框。我的问题是:

(2.1)我可以使用SELECT的innerHTML属性(或者甚至包含

DynWrite函数)并以这种形式更新一些选择框上的某些

活动? (我问,因为我看到了使用Option对象的方式,并且假设它不像innerHTML解决方案那样可移植。)


(2.2)我应该使用XmlHttpRequest对象(它在IE中等效于

ActiveX - 与在Beta Google搜索网站中使用的方式相同)或者

i必须考虑使用像jsrs这样的东西:
http://www.ashleyit.com/rs/main。 htm (但是我看到它使用浏览器嗅探

以某种方式测试像document.all或document.layers这样的对象我认为不应该是
这样 - 最好的是使用对象

检测系统)。


(3)有没有人知道一个美化破坏的JavaScript代码的项目

(如上面提到的测试版谷歌网站上的as.js使用浏览器

文本框独立自动完成解决方案)。


(4)我听说过''这个''关键字麻烦es,所以一般来说我的

问题是 - 我必须使用例如

功能MyConstructor(){

var myRef = this;

this.myMethod = function(){

/ *使用myRef代替关键字''this''* /

}

}


MyConstructor.myStaticPublicMethod(){/ *方法绑定到

MyConstructor函数对象* /

var myRef = this;

/ *使用myRef代替关键字''this''* /

}


我认为那是所有我的问题,将非常感谢您的回答(我尝试了这个帖子尽可能清晰可读)。

BR

Luke M 。

Welcome
I have read the in the faq from jibbering about the generic
DynWrite, but i also realized that is uses only innerHTML feature of
HTML objects.
(1) Is there a DOM function which is very similar to innerHTML property
eg. (my guess) setInnerNodeAsText or sth... ?

I want to write function which will be dynamically updateing some of my
select boxes. My question is:
(2.1) Can i use innerHTML property of SELECT (or even incorporate
DynWrite function) and in such form update some selects boxes on some
event ? (i ask because i saw the way which uses Option object, and
assumed is it not as portable as innerHTML solution).

(2.2) Should i use XmlHttpRequest object (and it equivalent in IE from
ActiveX - in the same way as it is used in Beta Google search site) or
i must consider using something like jsrs:
http://www.ashleyit.com/rs/main.htm (but i saw it uses browser sniffing
in a way of testing objects like document.all or document.layers which
in my opinion should not be this way - the best is to use object
detection system).

(3) Does anyone know a project which beautifies harshed JavaScript code
(like as.js from mentioned above beta google site which uses browser
independent autocomplete solution for text boxes).

(4) I have heard about ''this'' keyword troubles, so generally my
question is - do i have to use eg
funtion MyConstructor() {
var myRef = this;
this.myMethod = function() {
/* use myRef instead of keyword ''this'' */
}
}

MyConstructor.myStaticPublicMethod() { /* method tied up to
MyConstructor function object */
var myRef = this;
/* use myRef instead of keyword ''this'' */
}

I think thats all my questions, would be appreciate for answer (i tried
to make this post as legible as i could).
BR
Luke M.

推荐答案

> (1)是否有一个与innerHTML属性非常相似的DOM函数


不,你必须自己创建每个元素。
> (1) Is there a DOM function which is very similar to innerHTML property

No, you have to create each element yourself.
( 2.1)我可以使用SELECT的innerHTML属性(或者甚至包含DynWrite函数)并以这种形式更新某些
事件中的一些选择框吗? (我问,因为我看到了使用Option对象的方式,并且
假设它不像innerHTML解决方案那样可移植)。


Option对象和innerHTML都是可移植的,几乎每个浏览器都由

实现。选项对象比innerHTML早了一年或者两个,但是它们都用在我听说过的每个JS浏览器实现中。

(2.2)我应该使用XmlHttpRequest对象(它在IE中等效于ActiveX - 与Beta版Google搜索网站中使用的方式相同)或者
我必须考虑使用像jsrs这样的东西:
http://www.ashleyit.com/rs/main.htm (但我看到它使用浏览器嗅探方式来测试像document.all或document.layers这样的对象,我认为不应该这样 - 最好的是使用对象
检测系统)。


我会使用XMLHTTPObject,因为它几乎相同

无处不在(一旦你创建了对象。)

(3)有没有人知道一个美化苛刻的JavaScript代码的项目
(如上面提到的使用浏览器
独立自动完成解决方案的文本框的as.js)。


通过缩进(1)运行它然后运行一些:%s / gvar / realVarName / g过滤器

它在VIM中。

(4)我听说''这个''关键字有问题,所以一般来说我的问题是 - 我是否必须使用例如
功能MyConstructor(){
var myRef = this;
this.myMethod = function(){
/ *使用myRef代替关键字''this''* /
}
}
MyConstructor.myStaticPublicMethod(){/ *方法绑定到MyConstructor函数对象* /
var myRef = this;
/ *使用myRef而不是关键字''this''* /
}


两者都没有......这个是调用它的函数的实例。对于

示例,如果您的构造函数被调用:newObject = new

MyConstructor();

则newObject.this == newObject。这对于传递

对象作为参数最有用;例如,使用表单验证器,您可以使用

< form onsubmit =" validate(this)">然后你的验证函数

可以阅读

函数验证(f){

firstFormElement = f.elements [0];

...

}

我认为这就是我的所有问题,我会很感激回答(我试过这个帖子让这篇文章清晰可见我可以)。
BR
Luke M。
(2.1) Can i use innerHTML property of SELECT (or even incorporate
DynWrite function) and in such form update some selects boxes on some
event ? (i ask because i saw the way which uses Option object, and
assumed is it not as portable as innerHTML solution).
The Option object and innerHTML are both portable, implemented by
almost every browser. The option object predates innerHTML by a year or
two, but they are both used in every JS browser implementation that I
have heard of.
(2.2) Should i use XmlHttpRequest object (and it equivalent in IE from
ActiveX - in the same way as it is used in Beta Google search site) or
i must consider using something like jsrs:
http://www.ashleyit.com/rs/main.htm (but i saw it uses browser sniffing
in a way of testing objects like document.all or document.layers which
in my opinion should not be this way - the best is to use object
detection system).
I would use XMLHTTPObject simply because it is pretty much the same
everywhere (once you have created the object.)
(3) Does anyone know a project which beautifies harshed JavaScript code
(like as.js from mentioned above beta google site which uses browser
independent autocomplete solution for text boxes).
Run it thru indent(1) then run a few :%s/gvar/realVarName/g filters on
it in VIM.
(4) I have heard about ''this'' keyword troubles, so generally my
question is - do i have to use eg
funtion MyConstructor() {
var myRef = this;
this.myMethod = function() {
/* use myRef instead of keyword ''this'' */
}
}

MyConstructor.myStaticPublicMethod() { /* method tied up to
MyConstructor function object */
var myRef = this;
/* use myRef instead of keyword ''this'' */
}
Neither... "this" is the instance of the function that calls it. For
example, if your constructor was called thus: newObject = new
MyConstructor();
then newObject.this == newObject. this is most useful for passing
objects as arguments; for example, using a form validator, you may use
<form onsubmit="validate(this)"> and then your validation function
could read
function validate(f) {
firstFormElement = f.elements[0];
...
}
I think thats all my questions, would be appreciate for answer (i tried
to make this post as legible as i could).
BR
Luke M.






> (1)是否有一个与innerHTML属性非常相似的DOM函数


不,你必须自己创建每个元素。
> (1) Is there a DOM function which is very similar to innerHTML property

No, you have to create each element yourself.
( 2.1)我可以使用SELECT的innerHTML属性(或者甚至包含DynWrite函数)并以这种形式更新某些
事件中的一些选择框吗? (我问,因为我看到了使用Option对象的方式,并且
假设它不像innerHTML解决方案那样可移植)。


Option对象和innerHTML都是可移植的,几乎每个浏览器都由

实现。选项对象比innerHTML早了一年或者两个,但是它们都用在我听说过的每个JS浏览器实现中。

(2.2)我应该使用XmlHttpRequest对象(它在IE中等效于ActiveX - 与Beta版Google搜索网站中使用的方式相同)或者
我必须考虑使用像jsrs这样的东西:
http://www.ashleyit.com/rs/main.htm (但我看到它使用浏览器嗅探方式来测试像document.all或document.layers这样的对象,我认为不应该这样 - 最好的是使用对象
检测系统)。


我会使用XMLHTTPObject,因为它几乎相同

无处不在(一旦你创建了对象。)

(3)有没有人知道一个美化苛刻的JavaScript代码的项目
(如上面提到的使用浏览器
独立自动完成解决方案的文本框的as.js)。


通过缩进(1)运行它然后运行一些:%s / gvar / realVarName / g过滤器

它在VIM中。

(4)我听说''这个''关键字有问题,所以一般来说我的问题是 - 我是否必须使用例如
功能MyConstructor(){
var myRef = this;
this.myMethod = function(){
/ *使用myRef代替关键字''this''* /
}
}
MyConstructor.myStaticPublicMethod(){/ *方法绑定到MyConstructor函数对象* /
var myRef = this;
/ *使用myRef而不是关键字''this''* /
}


两者都没有......这个是调用它的函数的实例。对于

示例,如果您的构造函数被调用:newObject = new

MyConstructor();

则newObject.this == newObject。这对于传递

对象作为参数最有用;例如,使用表单验证器,您可以使用

< form onsubmit =" validate(this)">然后你的验证函数

可以阅读

函数验证(f){

firstFormElement = f.elements [0];

...

}

我认为这就是我的所有问题,我会很感激回答(我试过这个帖子让这篇文章清晰可见我可以)。
BR
Luke M。
(2.1) Can i use innerHTML property of SELECT (or even incorporate
DynWrite function) and in such form update some selects boxes on some
event ? (i ask because i saw the way which uses Option object, and
assumed is it not as portable as innerHTML solution).
The Option object and innerHTML are both portable, implemented by
almost every browser. The option object predates innerHTML by a year or
two, but they are both used in every JS browser implementation that I
have heard of.
(2.2) Should i use XmlHttpRequest object (and it equivalent in IE from
ActiveX - in the same way as it is used in Beta Google search site) or
i must consider using something like jsrs:
http://www.ashleyit.com/rs/main.htm (but i saw it uses browser sniffing
in a way of testing objects like document.all or document.layers which
in my opinion should not be this way - the best is to use object
detection system).
I would use XMLHTTPObject simply because it is pretty much the same
everywhere (once you have created the object.)
(3) Does anyone know a project which beautifies harshed JavaScript code
(like as.js from mentioned above beta google site which uses browser
independent autocomplete solution for text boxes).
Run it thru indent(1) then run a few :%s/gvar/realVarName/g filters on
it in VIM.
(4) I have heard about ''this'' keyword troubles, so generally my
question is - do i have to use eg
funtion MyConstructor() {
var myRef = this;
this.myMethod = function() {
/* use myRef instead of keyword ''this'' */
}
}

MyConstructor.myStaticPublicMethod() { /* method tied up to
MyConstructor function object */
var myRef = this;
/* use myRef instead of keyword ''this'' */
}
Neither... "this" is the instance of the function that calls it. For
example, if your constructor was called thus: newObject = new
MyConstructor();
then newObject.this == newObject. this is most useful for passing
objects as arguments; for example, using a form validator, you may use
<form onsubmit="validate(this)"> and then your validation function
could read
function validate(f) {
firstFormElement = f.elements[0];
...
}
I think thats all my questions, would be appreciate for answer (i tried
to make this post as legible as i could).
BR
Luke M.






2005年11月22日08:55,卢克Matuszewski写道:


[snip]
On 22/11/2005 08:55, Luke Matuszewski wrote:

[snip]
(1)是否存在与innerHTML
属性非常相似的DOM函数,例如。 (我猜)setInnerNodeAsText或...... ......


无法传递包含HTML的字符串并将其解析并将

插入到文档树中。但是,表示了文本节点。

例如,


< p id =" myP">一些< em>强调< / em> ;文本。< / p>


将创建以下结构:


p(元素)

+ - ''Some''(#text)

+ - em(元素)

| + - ''强调''(#text)

+ - ''text。''(#text)


文本节点有数据属性,这可以修改:


var p = document.getElementById(''myP''),

text = p.firstChild;


text.data =''有些不同'';


导致相当于:


< p id =" myP">一些不同的< em>强调< / em>文本。< / p>


使用

document.createTextNode方法也可以创建其他文本节点。


[snip]

(2.1)我可以使用SELECT的innerHTML属性(或者甚至包含
DynWrite函数)并以这种形式更新一些选择框中的一些
活动?


毫无疑问,但我不太可能使用它。然后,你还没有解释你想要做什么。

(我问,因为我看到了使用Option对象的方式,并假设是
它不像innerHTML解决方案那样可移植)。


相反。使用innerHTML属性的可移植性较差。


Option构造函数是源自NN4的事实上的函数,并且

已经得到了相当广泛的支持。虽然W3C DOM方法可以占据它的位置,但由于

更大的支持,Option构造函数仍然是首选。

(2.2)应该我使用XmlHttpRequest对象[...]或者我必须考虑使用像jsrs这样的东西:


要做什么?你真的应该停止提问而不说明他们背后的

目的。


[snip]

(4)我听说过关于''这个''关键字麻烦,[...]
(1) Is there a DOM function which is very similar to innerHTML
property eg. (my guess) setInnerNodeAsText or sth... ?
There is no way to pass a string containing HTML and have it parsed and
inserted into the document tree. However, text nodes are represented.
For example,

<p id="myP">Some <em>emphasised</em> text.</p>

would create the following structure:

p (element)
+- ''Some '' (#text)
+- em (element)
| +- ''emphasised'' (#text)
+- '' text.'' (#text)

Text nodes have a data property and this can be modified:

var p = document.getElementById(''myP''),
text = p.firstChild;

text.data = ''Some different '';

resulting in the equivalent of:

<p id="myP">Some different <em>emphasised</em> text.</p>

It''s also possible to create additional text nodes, using the
document.createTextNode method.

[snip]
(2.1) Can i use innerHTML property of SELECT (or even incorporate
DynWrite function) and in such form update some selects boxes on some
event ?
Undoubtedly, but it''s unlikely that I''d use it. Then again, you haven''t
explained what you''re trying to do.
(i ask because i saw the way which uses Option object, and assumed is
it not as portable as innerHTML solution).
On the contrary. Using the innerHTML property is less portable.

The Option constructor is a de facto function originating from NN4, and
has gathered quite widespread support. Though W3C DOM methods can take
its place, the Option constructor is still preferred by some due to
greater support.
(2.2) Should i use XmlHttpRequest object [...] or i must consider
using something like jsrs:
To do what? You really should stop asking questions without stating the
purpose behind them.

[snip]
(4) I have heard about ''this'' keyword troubles, [...]




您是否真的阅读了我发布到您之前的帖子的后续内容?

有/没有'''麻烦''。


[snip]


Mike


-

Michael Winter

前缀主题[新闻],然后通过电子邮件回复。



Did you actually read the follow-ups I posted to your previous threads?
There are /no/ ''troubles''.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.


这篇关于通用innerHTML功能和其他小问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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