相当于'data dumper'的javascript [英] javascript equivalent of 'data dumper'

查看:56
本文介绍了相当于'data dumper'的javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有,


我是一个沉重的perl用户,而不是一个java脚本用户,而且是

想知道...


perl有一个非常好用的实用程序,叫做Data :: Dumper,允许你转储任意数据结构的内容。我想用

用javascript做同样的事情。


打印数据::转储器(文件)

打印数据:: Dumper(document.form)


等等。


有没有可以让你这样做的工具?


此外,是否有任何特殊原因导致某个函数无法获得
看到某个变量?我正在用以下形式调用javascript:


< script type =" text / javascript" >

函数download_submit()

{

alert(document.form.filecheckbox.value);

}

< / script>


< form name =" form">

< a href = javascript :download_submit()">

< img src =" ...." ...>

< / a>


< input name =" filecheckbox"值= QUOT;&设为myVal QUOT; type =" checkbox"

onchange =" this.form.foldercheckbox.value = this.valu e"

hey all,

I''m a heavy perl user, not so much a java script user, and was
wondering...

perl has an extremely nice utility called Data::Dumper, which allows
you to dump out the contents of an arbitrary data structure. I''d like
to do the same with javascript.

print Data::Dumper(document)
print Data::Dumper(document.form)

etc. etc. etc.

Is there a utility that lets you do this?

Also, is there any particular reason why a function wouldn''t be able to
see a certain variable? I''m calling javascript with the form:

<script type="text/javascript" >
function download_submit()
{
alert(document.form.filecheckbox.value);
}
</script>

<form name="form">
<a href="javascript:download_submit()">
<img src="...." ...>
</a>

<input name="filecheckbox" value="myval" type="checkbox"
onchange="this.form.foldercheckbox.value=this.valu e"



< / form>


出于某种原因,当我选中复选框时,我看不到结果在

javascript中。我想转出文档,看看javascript函数看到的确切* *

...


非常感谢任何帮助。 ..


Ed


</form>

For some reason, when I check the checkbox, I don''t see the results in
the javascript. I''d like to dump out the document to see exactly *what*
the javascript function is seeing...

Thanks much for any help...

Ed

推荐答案

horos写道:
嘿所有,

我是一个非常重要的perl用户,而不是一个java脚本用户,并且想知道......

print Data ::翻车机(文件)
打印数据::翻车机(document.form)


我从未见过这样的事情。但如果您使用的是Mozilla

浏览器套件,那么有大量用于Web开发的插件,包括

DOM检查器,javascript调试器,CSS工具等等。我在想

,也许DOM检查员会让你做你想做的事情。

做。

https://addons.update.mozilla.org/ex ... eloper%20Tools

出于某种原因,当我选中复选框时,我在javascript中看不到结果
。我想转出文档,看看确切的
* javascript函数看到了什么......
hey all,

I''m a heavy perl user, not so much a java script user, and was
wondering...

print Data::Dumper(document)
print Data::Dumper(document.form)

I have never seen anything like this. But if you are using the Mozilla
browser suite there are a ton of plugins for web development, including
DOM inspectors, javascript debuggers, CSS tools, etc. I am thinking
that maybe the DOM inspector would let you do what you are trying to
do.

https://addons.update.mozilla.org/ex...eloper%20Tools

For some reason, when I check the checkbox, I don''t see the results in the javascript. I''d like to dump out the document to see exactly *what* the javascript function is seeing...




嗯,在你的例子中,当你选中复选框时,

filecheckbox的值被重新赋值为myval1,这是filecheckbox的初始值

,所以这是为什么你没有看到

的变化呢?


我稍微缩短了你的onclick代码并硬编码了一个值

你好,但它对我来说很好。


< a href =" javascript :download_submit()"> Show Alert< ; / a>

< input name =" filecheckbox"值= QUOT; myval1" type =" checkbox"

onclick =" this.value =''hello''">


我省略了javascript功能很简单,但如果你点击超链接显示警报它以myval1提醒,但如果我

,请选中该复选框,然后点击显示提醒。它以你好的方式发出警告


- brian



Well, in your example, when you check the checkbox, the value of
filecheckbox was being re-assigned the value of "myval1", which was the
initial value of filecheckbox, so is this why you weren''t seeing a
change, maybe?

I shortened your onclick code a little bit and hard coded a value of
hello, but it works fine for me.

<a href="javascript:download_submit()">Show Alert</a>
<input name="filecheckbox" value="myval1" type="checkbox"
onclick="this.value=''hello''">

I''ve omitted the javascript function for simplicitly sake, but if you
click the hyperlink "Show Alert" it alerts with "myval1", but if I
check the checkbox and click "Show Alert" it alerts with "hello"

-- brian


是的,我将onchange更改为onclick,并且它工作了......谢谢。


就Dumper项目而言,我尝试了DOM检查员,他们似乎在HTML方面工作得很好围栏,但不是在JavaScript

方面。他们解析HTML来提出标签,但是不要做什么来找出一个给定的浏览器正在使用的javascript解释器然后去找到它的属性和它们的价值。


可惜,真的,因为这会加速我的开发至少

一个数量级,如果不是更多。如果有人知道像这样的话,我很想听听。


干杯,


Ed

yes, I changed onchange to onclick, and it worked... Thanks.

As far as the Dumper item goes, I tried DOM inspectors, and they seem
to work great on the HTML side of the fence, but not on the JavaScript
side. They parse the HTML to come up with the tags, but don''t do the
heavy lifting of finding out what javascript interpreter a given
browser is using and then going in to find its attributes and their
values.

A pity, really, because this would speed up my development by at least
an order of magnitude, if not more. If anyone knows of something like
this, I''d love to hear about it.

Cheers,

Ed


horos写道:

[...]
horos wrote:
[...]
此外,是否有函数无法看到某个变量的任何特殊原因?我正在用以下形式调用javascript:

< script type =" text / javascript" >
函数download_submit()
{
alert(document.form.filecheckbox.value);


alert(document.forms.filecheckbox.value);

------------------- ----------- ^


简单的语法错误,你正在解决*表格*集合。


[ ...]< input name =" filecheckbox"值= QUOT;&设为myVal QUOT; type =" checkbox"
onchange =" this.form.foldercheckbox.value = this.valu e"
Also, is there any particular reason why a function wouldn''t be able to
see a certain variable? I''m calling javascript with the form:

<script type="text/javascript" >
function download_submit()
{
alert(document.form.filecheckbox.value);
alert(document.forms.filecheckbox.value);
------------------------------^

Simple syntax error, you are addressing the *forms* collection.

[...] <input name="filecheckbox" value="myval" type="checkbox"
onchange="this.form.foldercheckbox.value=this.valu e"
> < / form>

出于某种原因,当我选中复选框时,我看不到javascript中的结果。我想转出文档,看看* javascript函数正在看到什么*
...
> </form>

For some reason, when I check the checkbox, I don''t see the results in
the javascript. I''d like to dump out the document to see exactly *what*
the javascript function is seeing...




Onchange有点令人讨厌复选框。根据HTML规范,

onchange会在元素失去焦点时触发。但是这并不是真的有一个复选框,所以Geko浏览器基本上作为一个onclick来启动onchange

。另一方面,IE遵循规范

并在复选框失去焦点时触发onchange。


这很令人困惑,好像你说3复选框具有不同的

onchange事件,当你点击一个没有任何反应时,当你点击

下一个点击时,你点击的第一个点击火灾,当

你点击页面中的其他地方,第二个点火。用户

将事件与下面的点击相关联,而不是实际导致事件发生的事件,因此会产生混淆。


解决方案是使用onclick并检查复选框的状态

查看是否已选中,然后运行该事件。东西

喜欢:


< input ... type =" checkbox" onclick ="

this.form.foldercheckbox.value =(this.checked)? this.value:'''';

">

非常感谢任何帮助...



Onchange is kinda nasty with a checkbox. According to the HTML spec,
onchange fires when the element loses focus. But this doesn''t really
make sense with a checkbox, so Geko browsers fire the onchange
essentially as an onclick. IE, on the other hand, follows the spec
and fires the onchange when the checkbox loses focus.

This is very confusing as if you have say 3 checkboxes with different
onchange events, when you click one nothing happens, when you click
the next one the onchange from the first on you clicked fires, when
you click somewhere else in the page, the second one fires. The user
associates the event with the following click, not the one that
actually causes the event to happen, hence confusion.

The solution is to use onclick and check the state of the checkbox to
see if it''s checked or not, then run the event or not. Something
like:

<input ... type="checkbox" onclick="
this.form.foldercheckbox.value = (this.checked)? this.value : '''';
">

Thanks much for any help...




没问题。

-

Rob



No problem.
--
Rob


这篇关于相当于'data dumper'的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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