国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

為radio類型的INPUT添加客戶端腳本(附加實現JS來禁用onClick事件思路代碼)

2019-11-21 00:08:32
字體:
來源:轉載
供稿:網友
下面的例子將展示其結果是沒有重載顯示提交。
當用戶選擇一個選項上面,一個函數叫做“getVote()”執行。該功能所引發的“的OnClick”事件
復制代碼 代碼如下:

<html>
<head>
<script type="text/javascript">
function getVote(int)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("poll").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","poll_vote.php?vote="+int,true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="poll">
<h3>Do you like PHP and AJAX so far?</h3>
<form>
Yes:
<input type="radio" name="vote"value="0" onclick="getVote(this.value)" />
<br />No:
<input type="radio" name="vote"value="1" onclick="getVote(this.value)" />
</form>
</div>
</body>
</html>


The getVote() function does the following:
Create an XMLHttpRequest object
Create the function to be executed when the server response is ready
Send the request off to a file on the server
Notice that a parameter (vote) is added to the URL (with the value of the yes or no option)
判斷控件的disabled屬性是不是true,是的話return false;實現禁用radio的onclick事件并可再次啟用它
方法一:(同時實現禁用,重新啟用功能,只能針對button text類型的INPUT,對div無法禁用其onclick事件)
<input type="button" value="A button. Click me to see the alert box." onclick="alert('I am clicked.');" id="cmd1" />
<br/>
<input type="button" value="Click me to disable the first button" onclick="document.getElementById('cmd1').disabled=true;" />
<br/>
方法二,三:(實現移除radio的onclick事件,需再次重新注冊事件,可以禁用div的onclick事件)
<input type="button" value="Click me to disable the onclick event on first button" onclick="document.getElementById('cmd1').onclick=function(){};" />

<br/>
三:
<input type="button" value="Click me to disable the onclick event on first button" onclick="document.getElementById('cmd1').onclick=null;" />
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平顶山市| 灌阳县| 崇文区| 纳雍县| 连州市| 绍兴县| 奉化市| 莎车县| 清水河县| 大庆市| 新巴尔虎右旗| 满城县| 鄯善县| 阿勒泰市| 井陉县| 永州市| 雷波县| 广安市| 漳浦县| 锦州市| 玛曲县| 佛山市| 彩票| 上林县| 永年县| 汶川县| 鹿泉市| 漠河县| 娱乐| 重庆市| 长海县| 甘肃省| 合江县| 武冈市| 崇仁县| 无极县| 新竹市| 西峡县| 醴陵市| 平昌县| 新龙县|