本文介绍了相当于'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

推荐答案




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

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有点令人讨厌复选框。根据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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 05:00