欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2010年11月11日 15:21:50   作者:  
為radio類型的INPUT添加客戶端腳本(附加實現(xiàn)JS來禁用onClick事件思路代碼),需要的朋友可以參考下。
下面的例子將展示其結(jié)果是沒有重載顯示提交。
當用戶選擇一個選項上面,一個函數(shù)叫做“getVote()”執(zhí)行。該功能所引發(fā)的“的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;實現(xiàn)禁用radio的onclick事件并可再次啟用它
方法一:(同時實現(xiàn)禁用,重新啟用功能,只能針對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/>
方法二,三:(實現(xiàn)移除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;" />

相關(guān)文章

最新評論