[英]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> <!-- "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。 此時,不可能給出令人滿意的答案,您將必須進行逐步調查。 首先關注並在此處發布結果。
<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.