jsp页面怎么根据radio的不同执行不同的div中的内容

jsp页面怎么根据radio的不同执行不同的div中的内容,第1张

假如radio名称为r,添加onclick事件showDIV();div1 id为div1,div2id为div2,设置属性style="display:none"

function showDIV(){

if(document.getElementsByName("r")[0].checked){

document.getElementById("div1").style.display=""

document.getElementById("div2").style.display="none"

}else{

document.getElementById("div1").style.display="none"

document.getElementById("div2").style.display=""

}

}

首先添加给radio添加绑定单击事件,可以直接使用onclick="",也可以用jquery绑定;

$(function() {

showCont()

$("input[name=price_type]").click(function() {

showCont()

})

})

function showCont(){

var normal = document.getElementById("price_type1")

var special = document.getElementById("price_type2")

if (normal.checked) {

$("#sellInfo2").hide()

$("#sellInfo1").show()

}

if (special.checked) {

$("#sellInfo1").hide()

$("#sellInfo2").show()

}

}

结果:


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

原文地址:https://54852.com/bake/7927076.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存