调用JavaScript for Checkbox. [英] Call JavaScript for Checkbox.
问题描述
我遵循UI的大家好
1)
我必须在一页中潜水
每个Div包含
文字框和
一个复选框
和按钮
在BUtton上单击它将检查复选框是否被选中.
为此,我编写了Javascript.
2)@nd Div包含相同的内容.
想要相同的操作
3)
我在按钮单击时将ckebox ID传递给javascript函数.
但显示空值.
代码如下:
Hello Guys I Have Following UI
1)
I have To Div In one page
each Div Contain
TextBox and
One Check Box
And Button
On BUtton Click It Will Check That CheckBox Is Checked Or Not.
For That I write Javascript.
2) @nd Div Contain Same thing.
want to d same opertion
3)
I m Passing ckebox Id for javascript function on button click.
but it show null value.
code arte as follow:
<div id="div1">
<textbox>
<check box id="checkbox1">
<button önclientckick="ischecked(checkbox1)">
</div>
<div id="div2">
<textbox>
<check box id="checkbox2">
<button önclientckick="ischecked(checkbox2)">
</div>
现在
javascript函数
now
javascript function
function IsChecked(Id)
{
alert(Id);
var chk = document.getElementById(Id);
alert(chk);//this will give null value..
if(!chk.checked)
{
alert("Please check Terms and Condition checkbox");
return false;
}
else
{
return confirm("Are you sure want to submit");
}
}
alert(chk);//这将给出空值..
我应该怎么做???????
alert(chk);//this will give null value..
what should i do??????
推荐答案
请尝试以下操作..
Try the below..
<div id="div1">
<input type="text"/>
<input type="checkbox" id="checkbox1"/>
<input type="button" onclick="ischecked('checkbox1');" value="click1" />
</div>
<div id="div2">
<input type="text"/>
<input type="checkbox" id="checkbox2"/>
<input type="button" onclick="ischecked('checkbox2');" value="click1" />
</div>
function ischecked(Id)
{
alert(Id);
var chk = document.getElementById(Id);
alert(chk);//this will give null value..
if(!chk.checked)
{
alert("Please check Terms and Condition checkbox");
return false;
}
else
{
return confirm("Are you sure want to submit");
}
}
谢谢..
Thanks..
这很好用
This works fine
<html>
<head>
<title>
chkbx
</title>
<script>
function ischecked(Id)
{
var chk = document.getElementById(Id);
if(!chk.checked)
{
alert("Please check Terms and Condition "+Id);
return false;
}
else
{
return confirm("Are you sure want to submit "+Id);
}
}
</script>
</head>
<body>
<div id="div1">
<input type="text"/>
<input type="checkbox" id="checkbox1"/>
<input type="button" önclick="return ischecked('checkbox1');" value="click1" />
</div>
<div id="div2">
<input type="text"/>
<input type="checkbox" id="checkbox2"/>
<input type="button" önclick="return ischecked('checkbox2');" value="click2" />
</div>
</body>
</html>
var chk = document.getElementById(objId);
赋予Null值.
在那里,它不能走得更远!.
无论是否选中!
var chk = document.getElementById(objId);
Give Null Value.
There fore it can not go further!.
for either it is checked or not!
这篇关于调用JavaScript for Checkbox.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!