[英]Function is not working on radio button onclick
JavaScript function (here f1()
) is not getting called on radio button (here id= iprange
) onclick
event. 在单选按钮(此处id = iprange
)的onclick
事件中未调用JavaScript函数(此处为f1()
)。
HTML HTML
function f1() { alert('yes'); }
<form role="form"> <div class="box-body"> <label> <input type="radio" name="optionsRadios" id="fullscan1" value="option1" /> Full Scan </label> <!-- "IP Range" is the radio button that should show a "yes" alert. --> <label> <input type="radio" name="optionsRadios" id="iprange" value="option2" onclick="f1();" /> IP Range </label> From: <input type="text" id="text1"> To: <input type="text" id="text2"> <label> <input type="radio" name="optionsRadios" id="subnet" value="option3" /> Subnet </label> <input type="text" id="text3"> <button class="btn btn-danger">Scan</button> </div> </form>
@Suresh Kota . @Suresh Kota。 At this point its impossible to give an satisfying answer, you'll have to do a step-by-step-investigation. 此时,不可能给出令人满意的答案,您将必须进行逐步调查。 Start with following and post your result here. 首先关注并在此处发布结果。
<head>
....
<script> // your script tag, I assume it looks like this
$(document).ready(function() {
/* some code */
});
// now include your function as last line outside document ready
function f1() {alert('yes');};
</script>
<!-- Make sure this is the only script tag in your html -->
....
</head>
If that doesn't help, rename your function, eg function xxx() {alert('yes');};
如果那没有帮助,请重命名您的函数,例如function xxx() {alert('yes');};
and same with onclick-attribute in input-tag: onclick="xxx()"
. 与input-tag中的onclick-attribute相同: onclick="xxx()"
。
When having no succes, try directly: onclick="alert('yes')"
如果没有成功,请直接尝试: onclick="alert('yes')"
If that all not work, there's something inside your document.ready that manipulates the button, and you should post that code. 如果所有方法都不起作用,则document.ready内部有一些操作按钮的操作,您应该发布该代码。
Try this one: 试试这个:
<input type="radio" name="optionsRadios" onclick="handleClick(this);" value="option1" />
<input type="radio" name="optionsRadios" onclick="handleClick(this);" value="option2" />
...
<script>
function handleClick(myRadio) {
alert('New value: ' + myRadio.value);
}
</script>
<label onclick="red()"><input type="radio" name="colors" id="red">Red</label>
or 要么
<label onclick="red()"><input type="radio" name="colors" id="red"></label> <label for="red">Red</label>
<script>
function red(){
alert('i am red');
}
</script>
if you want to call onclick function on radio button then you can use like this, it will work for you 如果您想在单选按钮上调用onclick函数,则可以像这样使用,它将为您工作
Note: we have to call on function on label instead of radio button 注意:我们必须调用标签上的函数而不是单选按钮
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.