html单选框和复选框

html单选框和复选框,第1张

单选这样写:<input ID="apple" name="fruit" type="radio" value ="Apple" /><Label for="apple">苹果</Label>

复选:

<input type="checkbox" name="fruit" value ="apple" ID="apple"><Label for="apple">苹果</Label>

如果多项的话,就直接for同样的ID,然后至少“苹果”变了文字而已,这个就是最好的方法了,没其他好的办法了

    初学对HTML进行了简单的学习以及记录,勿喷,只是记录一个过程,也希望对初学者有点帮助吧.

<!DOCTYPEhtml>

<html>

 label{

height : 20px

background :  chartreuse

float : none

 }

input[ type ="checkbox"]{

width :20px

height :20px

display : inline-block

text-align : center

vertical-align : middle 

line-height : 18px

position : relative}

/*未选中的状态*/

input[ type ="checkbox"]::before{

content : ""

position : absolute

top :0

left : 0

background : #fff

width : 100%

height : 100%

border : 1px solid #d9d9d9}

/*选中的状态*/

input[ type ="checkbox"]:checked::before{

content : "\2713"background-color : #fff // \2713 点击到特殊符号表

position : absolutetop : 0left : 0width :100%

border : 1px solid #e50232

color :#e50232

font-size : 20pxfont-weight : bold}

</style>

// 使用需要导入<script  language="JavaScript"src="js/ jquery.js(点击进入链接) "></script> 

  $(":checkbox").click( function (){

        $( this ). attr ("checked",true)//设置当前选中checkbox的状态为checked

       $( this ).siblings(). attr ("checked",false)//设置当前选中的checkbox同级(兄弟级)其他checkbox状态为未选中

})

function chang( id ){

var idc= '#'+id

//获取是否选中 

var isChecked= $(idc).is(":checked")

// 发送到交互的数据

window .webkit.messageHandlers.jsToOcWithPrams.postMessage({"paramid":id,"paramflag":isChecked})

}

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/6107171.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-15
下一篇 2023-03-15

发表评论

登录后才能评论

评论列表(0条)

保存