[英]Change content with HTML radio buttons
我的网站上有以下代码。
<input type="radio" name="pricelist" onclick="online();" /> Show price with VAT
<br />
<input type="radio" name="pricelist" onclick="offline();" /> Show price without VAT
<br />
<span id="update"></span>
<script type="text/javascript">
function online(){
document.getElementById("update").innerHTML = "100$";
}
function offline(){
document.getElementById("update").innerHTML = "75$";
}
</script>
我希望当用户打开页面时显示“含增值税价格”。 不幸的是,它不适用于仅“检查”表单。
你们当中有人知道如何解决吗? :)
在document.ready上,通过JavaScript检查广播。
您可以为此使用onload事件,
<body onload="initial()">
<input id="vat" type="radio" name="pricelist" onclick="online();" /> Show price with VAT
<br />
<input id="novat" type="radio" name="pricelist" onclick="offline();" /> Show price without VAT
<br />
</body>
function initial(){
//automatically check the radio button
document.getElementById("vat").checked = true;
//call the function you want to call when page loads
online();
}
不要忘记将id
分别作为vat和novat添加到您的单选按钮中。
如果您想使用jQuery,则可以使用它的ready()
函数,该函数将在页面加载时执行,
$(document).ready(function(){
initial();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.