问题描述
我有一个网页,其中包含两个单选按钮和其他几个控件。
所以,为此,我在javascript中编写了一个函数进行验证。如果我的单选按钮在页面上可见它会正常工作。
但是,对于少数用户来说,这些单选按钮不应该是可见的,如果我保持为可见的虚假单选按钮没有渲染到页面源,然后其他验证也跳过。所以,在这种情况下,我需要检查我的页面是否有单选按钮。所以如何查看我的页面有单选按钮不是javascript。
谢谢和问候
Avinash
Hi,
I have one web page that contains two radio buttons and few other controls.
So,for that i wrote a function in javascript for validations.If my radio buttons are visible on page it will work fine.
But,For few users those radio buttons should not be visible so, if i kept as Visible false radio buttons are not rendering to page source then other validations are also skipping.So,In this kind of situation i need to check whether my page has radio buttons are not. so How to check my page has radio buttons are not in javascript.
Thanks & Regards
Avinash
推荐答案
var rbtNew = document.getElementById('rbtNew');
var rbtOld = document.getElementById('rbtOld');
if (rbtNew != null && rbtOld != null) {
if (rbtNew.checked == false && rbtOld.checked == false) {
alert("our Alert Message ");
return false;
}
}
在上面的代码中,rbtNew!= null表示页面源中存在单选按钮,否则它将具有空值。
In the above code rbtNew != null means radio button is exist in page source otherwise it will have null value.
这篇关于如何检查我的网页是否在Javascript中有单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!