繁体   English   中英

功能在单选按钮onclick上不起作用

[英]Function is not working on radio button onclick

在单选按钮(此处id = iprange )的onclick事件中未调用JavaScript函数(此处为f1() )。

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> &nbsp;&nbsp;&nbsp;&nbsp; <!-- "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"> &nbsp;&nbsp;&nbsp;&nbsp; <label> <input type="radio" name="optionsRadios" id="subnet" value="option3" /> Subnet </label> <input type="text" id="text3"> &nbsp;&nbsp;&nbsp;&nbsp; <button class="btn btn-danger">Scan</button> </div> </form> 

@Suresh Kota。 此时,不可能给出令人满意的答案,您将必须进行逐步调查。 首先关注并在此处发布结果。

<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>

如果那没有帮助,请重命名您的函数,例如function xxx() {alert('yes');};

与input-tag中的onclick-attribute相同: onclick="xxx()"

如果没有成功,请直接尝试: onclick="alert('yes')"

如果所有方法都不起作用,则document.ready内部有一些操作按钮的操作,您应该发布该代码。

试试这个:

<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>
要么
<label onclick="red()"><input type="radio" name="colors" id="red"></label> <label for="red">Red</label>

<script>
function red(){
 alert('i am red');
}
</script>

如果您想在单选按钮上调用onclick函数,则可以像这样使用,它将为您工作

注意:我们必须调用标签上的函数而不是单选按钮

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM