當前位置:編程學習大全網 - 源碼下載 - js怎樣判斷單選框是否被選中?

js怎樣判斷單選框是否被選中?

這樣:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>JQuery radio</title>

<script type="text/javascript" language="javascript" src="JavaScript/jquery-1.6.1.min.js" ></script>

<script type="text/javascript">

$(function () {?

$("input").click(function () {?

  if ($(this).attr("checked")) {?

    alert("選中了");?

  }?

});?

});?

</script>?

</head>?

<body>?

<input type="radio"/>?

</body>?

</html>

擴展資料:

註意事項

<form>

<input type="radio" id="radio1" />

<input type="button" οnclick="check()" value="選中" />

<input type="button" οnclick="uncheck()" value="取消" />

</form>

function check() {

//被選中

document.getElementById("radio1").checked = true

//被選中時,可以執行的方法

if(document.getElementById("radio1").checked == true){

console.log('==')

}

}

function uncheck() {

//不選中

document.getElementById("radio1").checked = false

//不被選中時,可以執行的方法

if(document.getElementById("radio1").checked == false){

console.log('++')

}?

}

  • 上一篇:2021年開運風水布局方位詳解 東北方喜神位
  • 下一篇:linux操作系統適合做什麽?
  • copyright 2024編程學習大全網