不能简单的确认()工作 [英] can't get simple confirm() to work
问题描述
在让onSubmit函数工作时遇到问题,根据选择的单选按钮,弹出
确认的位置。
这就是我所拥有的:
函数checkdel(){
if(document.getElementById [" rd_del []"]。value ==''1''){
确认(''你确定要删除这个文件吗?'');
}
}
......
< FORM NAME =" form1" ID = QUOT; form1的"行动= QUOT;的index.php PROCID = 5英寸?; method =" POST"
enctype =" application / x-www-form-urlencoded"目标= QUOT; _self" onSubmit =" return
checkdel();">
< div align =" left" class =" headerLG">是否要删除此文章?
& nbsp;< input name =" rb_del" ID = QUOT; rb_del"类型= QUOT;无线电"值= QUOT; 0"选中>否
< input name =" rb_del" ID = QUOT; rb_del"类型= QUOT;无线电"值= QUOT 1 QUOT;>是< / div>< p />
我试过了:
document.getElementById [" rd_del"]。value ==''1 ''
document.getElementById [" rd_del [1]"]。checked == true
我已查找DOM并查找例子,从我所看到的,我有正确格式化的
。
我也尝试过将''form1''放入的语法上面一行,但我只是
不能使它工作。
我缺少什么?只是一个线索会有所帮助!
感谢您的回复,
Liam
Having a problem getting a onSubmit function to work, to where it popsup a
confirmation depending on which radiobutton is selected.
Here''s what I have:
function checkdel() {
if (document.getElementById["rd_del[]"].value==''1'') {
confirm(''Are you sure you want to delete this file?'');
}
}
......
<FORM NAME="form1" ID="form1" action="index.php?procid=5" method="POST"
enctype="application/x-www-form-urlencoded" target="_self" onSubmit="return
checkdel();">
<div align="left" class="headerLG">Do you want to delete this article?
<input name="rb_del" id="rb_del" type="radio" value="0" checked>No
<input name="rb_del" id="rb_del" type="radio" value="1"> Yes </div><p />
I''ve tried:
document.getElementById["rd_del"].value==''1''
document.getElementById["rd_del[1]"].checked==true
I''ve looked up DOM and looked for examples, and from what I can see, I have
it formatted correctly.
I''ve also tried syntax that''s put the ''form1'' in the line above, but I just
can''t make it work.
What am I missing? Just a clue would help!
Thanks for any replies,
Liam
推荐答案
LRW写道:
在让onSubmit函数工作时遇到问题,根据选择的单选按钮,
弹出确认。
这是什么我有:
函数checkdel(){
if(document.getElementById [" rd_del []"]。value ==''1''){
确认(''你确定要删除这个文件吗?'');
}
}
.....
< FORM NAME =" form1" ID = QUOT; form1的"行动= QUOT;的index.php PROCID = 5英寸?;
method =" POST" ENCTYPE = QUOT;应用/ X WWW的窗体-urlencoded"目标= QUOT; _self"
onSubmit =" return checkdel();">
< div align =" left" class =" headerLG">是否要删除此
文章? & nbsp;< input name =" rb_del" ID = QUOT; rb_del"类型= QUOT;无线电"值= QUOT; 0"
已检查>否<输入名称=" rb_del" ID = QUOT; rb_del"类型= QUOT;无线电"值= QUOT 1 QUOT;>是< / div>< p
/>
我试过了:
document.getElementById [" rd_del"]。value ==''1 ''
document.getElementById [" rd_del [1]"]。checked == true
我查了一下DOM,找了一些例子,从我看到的,
我的格式正确。
我也尝试过将''form1''放在上面的行中的语法,但
我就是不能它有效。
我错过了什么?只是一个线索会有所帮助!
感谢您的回复,
Liam
Having a problem getting a onSubmit function to work, to where it popsup a confirmation depending on which radiobutton is selected.
Here''s what I have:
function checkdel() {
if (document.getElementById["rd_del[]"].value==''1'') {
confirm(''Are you sure you want to delete this file?'');
}
}
.....
<FORM NAME="form1" ID="form1" action="index.php?procid=5" method="POST" enctype="application/x-www-form-urlencoded" target="_self" onSubmit="return checkdel();">
<div align="left" class="headerLG">Do you want to delete this article? <input name="rb_del" id="rb_del" type="radio" value="0" checked>No <input name="rb_del" id="rb_del" type="radio" value="1"> Yes </div><p />
I''ve tried:
document.getElementById["rd_del"].value==''1''
document.getElementById["rd_del[1]"].checked==true
I''ve looked up DOM and looked for examples, and from what I can see, I have it formatted correctly.
I''ve also tried syntax that''s put the ''form1'' in the line above, but I just can''t make it work.
What am I missing? Just a clue would help!
Thanks for any replies,
Liam
您想在哪里开始?
>
它是document.getElementById() - 一个函数。括弧; square
括号用于对象/数组引用。
这个:
" rd_del [1]" ;
....虽然有点合法(在这一点上存在一些分歧)只是
用于传递名称中包含方括号的表单名称,
通常是为了让它成为php端的一个数组。它没有内在的
意思是javascript :''真实''JavaScript中的方括号不是
字符串字符,但是语言操作符 - 所以你好像是把JS数组引用与JS混淆了。
..value ==''1''
检查单选按钮的值没什么意义,它几乎就是你设置它的
。它是.checked属性,表示你想知道你想知道什么。好的,你怀疑了。要按
按名称引用第二个(是)按钮:
rb_del [1]
......因为JS从一个算起来。请注意,这是一个实际的数组引用
而不是字符串。
您也没有返回confirm()框的返回值,渲染
它很无用。好的,够了。不妨使用id(必须是
唯一)。
<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 // EN"
" http://www.w3.org/TR/html4/strict.dtd">
< html>
< head>
< title>无标题< / title>
< script type =" text / javascript">
//<![CDATA [
函数checkdel()
{
if(document.getElementById) (''rb_del_yes'')。选中)
返回确认(''你确定要删除这个文件吗?'');
else返回false; < br $>
}
//]]>
< / script>
< / head>
< body>
< form ID =" form1"行动= QUOT;的index.php PROCID = 5英寸?; method =" POST"
target =" _self"
enctype =" application / x-www-form-urlencoded" onsubmit =" return
checkdel()">
< div align =" left" class =" headerLG">是否要删除此文章?
& nbsp;< input name =" rb_del" ID = QUOT; rb_del_no"类型= QUOT;无线电" value =" 0"
checked =" checked"> No
< input name =" rb_del" ID = QUOT; rb_del_yes"类型= QUOT;无线电" value =" 1">是< / div>< p
/>
< input type =" submit" value ="删除文章" />
< / form>
< / body>
< / html>
[清理了一些其他项目]
Where would you like to start?
It''s document.getElementById() - a function. Parentheses; square
brackets are for object/array references.
This:
"rd_del[1]"
....while sort of legitimate (some disagreement on this point) is only
for passing a form name that includes square brackets in its name,
usually to make it an array on the php side. It has no intrinsic
meaning in javascript: ''real'' square brackets in JavaScript are not
string characters, but language operators - so you appear to be
confusing php array references with JS ones.
..value==''1''
Not much point in checking the value of a radio button, it pretty much
will be whatever you set it to. It''s the .checked property, indicating
you-know-what, that you''re looking for. OK, you suspected that. To
reference the second ("yes") button by name:
rb_del[1]
....as JS counts from one. Note that this is an actual array reference
and not a string.
You also didn''t return the return value of the confirm() box, rendering
it pretty useless. OK, enough. Might as well use an id (which must be
unique).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<script type="text/javascript">
//<![CDATA[
function checkdel()
{
if (document.getElementById(''rb_del_yes'').checked)
return confirm(''Are you sure you want to delete this file?'');
else return false;
}
//]]>
</script>
</head>
<body>
<form ID="form1" action="index.php?procid=5" method="POST"
target="_self"
enctype="application/x-www-form-urlencoded" onsubmit="return
checkdel()">
<div align="left" class="headerLG">Do you want to delete this article?
<input name="rb_del" id="rb_del_no" type="radio" value="0"
checked="checked">No
<input name="rb_del" id="rb_del_yes" type="radio" value="1">Yes</div><p
/>
<input type="submit" value="delete article" />
</form>
</body>
</html>
[cleaned up a few other items]
LRW写道:
在获取onSubmit函数时遇到问题根据选择了哪个单选按钮,
弹出确认。
这就是我所拥有的:
功能checkdel(){
如果( document.getElementById [" rd_del []"] .value ==''1''){
确认(''您确定要删除此文件吗?'');
}
}
.....
< FORM NAME =" form1" ID = QUOT; form1的"行动= QUOT;的index.php PROCID = 5英寸?;
method =" POST" ENCTYPE = QUOT;应用/ X WWW的窗体-urlencoded"目标= QUOT; _self"
onSubmit =" return checkdel();">
< div align =" left" class =" headerLG">是否要删除此
文章? & nbsp;< input name =" rb_del" ID = QUOT; rb_del"类型= QUOT;无线电"值= QUOT; 0"
已检查>否<输入名称=" rb_del" ID = QUOT; rb_del"类型= QUOT;无线电"值= QUOT 1 QUOT;>是< / div>< p
/>
我试过了:
document.getElementById [" rd_del"]。value ==''1 ''
document.getElementById [" rd_del [1]"]。checked == true
我查了一下DOM,找了一些例子,从我看到的,
我的格式正确。
我也尝试过将''form1''放在上面的行中的语法,但
我就是不能它有效。
我错过了什么?只是一个线索会有所帮助!
感谢您的回复,
Liam
Having a problem getting a onSubmit function to work, to where it popsup a confirmation depending on which radiobutton is selected.
Here''s what I have:
function checkdel() {
if (document.getElementById["rd_del[]"].value==''1'') {
confirm(''Are you sure you want to delete this file?'');
}
}
.....
<FORM NAME="form1" ID="form1" action="index.php?procid=5" method="POST" enctype="application/x-www-form-urlencoded" target="_self" onSubmit="return checkdel();">
<div align="left" class="headerLG">Do you want to delete this article? <input name="rb_del" id="rb_del" type="radio" value="0" checked>No <input name="rb_del" id="rb_del" type="radio" value="1"> Yes </div><p />
I''ve tried:
document.getElementById["rd_del"].value==''1''
document.getElementById["rd_del[1]"].checked==true
I''ve looked up DOM and looked for examples, and from what I can see, I have it formatted correctly.
I''ve also tried syntax that''s put the ''form1'' in the line above, but I just can''t make it work.
What am I missing? Just a clue would help!
Thanks for any replies,
Liam
您想在哪里开始?
>
它是document.getElementById() - 一个函数。括弧; square
括号用于对象/数组引用。
这个:
" rd_del [1]" ;
....虽然有点合法(在这一点上存在一些分歧)只是
用于传递名称中包含方括号的表单名称,
通常是为了让它成为php端的一个数组。它没有内在的
意思是javascript :''真实''JavaScript中的方括号不是
字符串字符,但是语言操作符 - 所以你好像是把JS数组引用与JS混淆了。
..value ==''1''
检查单选按钮的值没什么意义,它几乎就是你设置它的
。它是.checked属性,表示你想知道你想知道什么。好的,你怀疑了。要按
按名称引用第二个(是)按钮:
rb_del [1]
......因为JS从一个算起来。请注意,这是一个实际的数组引用
而不是字符串。
您也没有返回confirm()框的返回值,渲染
它很无用。好的,够了。不妨使用id(必须是
唯一)。
<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 // EN"
" http://www.w3.org/TR/html4/strict.dtd">
< html>
< head>
< title>无标题< / title>
< script type =" text / javascript">
//<![CDATA [
函数checkdel()
{
if(document.getElementById) (''rb_del_yes'')。选中)
返回确认(''你确定要删除这个文件吗?'');
else返回false; < br $>
}
//]]>
< / script>
< / head>
< body>
< form ID =" form1"行动= QUOT;的index.php PROCID = 5英寸?; method =" POST"
target =" _self"
enctype =" application / x-www-form-urlencoded" onsubmit =" return
checkdel()">
< div align =" left" class =" headerLG">是否要删除此文章?
& nbsp;< input name =" rb_del" ID = QUOT; rb_del_no"类型= QUOT;无线电" value =" 0"
checked =" checked"> No
< input name =" rb_del" ID = QUOT; rb_del_yes"类型= QUOT;无线电" value =" 1">是< / div>< p
/>
< input type =" submit" value ="删除文章" />
< / form>
< / body>
< / html>
[清理了一些其他物品]
Where would you like to start?
It''s document.getElementById() - a function. Parentheses; square
brackets are for object/array references.
This:
"rd_del[1]"
....while sort of legitimate (some disagreement on this point) is only
for passing a form name that includes square brackets in its name,
usually to make it an array on the php side. It has no intrinsic
meaning in javascript: ''real'' square brackets in JavaScript are not
string characters, but language operators - so you appear to be
confusing php array references with JS ones.
..value==''1''
Not much point in checking the value of a radio button, it pretty much
will be whatever you set it to. It''s the .checked property, indicating
you-know-what, that you''re looking for. OK, you suspected that. To
reference the second ("yes") button by name:
rb_del[1]
....as JS counts from one. Note that this is an actual array reference
and not a string.
You also didn''t return the return value of the confirm() box, rendering
it pretty useless. OK, enough. Might as well use an id (which must be
unique).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<script type="text/javascript">
//<![CDATA[
function checkdel()
{
if (document.getElementById(''rb_del_yes'').checked)
return confirm(''Are you sure you want to delete this file?'');
else return false;
}
//]]>
</script>
</head>
<body>
<form ID="form1" action="index.php?procid=5" method="POST"
target="_self"
enctype="application/x-www-form-urlencoded" onsubmit="return
checkdel()">
<div align="left" class="headerLG">Do you want to delete this article?
<input name="rb_del" id="rb_del_no" type="radio" value="0"
checked="checked">No
<input name="rb_del" id="rb_del_yes" type="radio" value="1">Yes</div><p
/>
<input type="submit" value="delete article" />
</form>
</body>
</html>
[cleaned up a few other items]
.....并感谢goddamgooglegroups的双重帖子!!!
.....and thanks to goddamgooglegroups for the double post !!!
这篇关于不能简单的确认()工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!