gpt4 book ai didi

javascript - 复选框不起作用

转载 作者:行者123 更新时间:2023-12-03 09:22:14 26 4
gpt4 key购买 nike

我有一个带有 JavaScript 复选框的简单代码。您可以在这个网站中看到前端:
englishforyou.ir
当您选中该复选框时,总价应显示新数字,但事实并非如此。
我的所有代码都在一页中:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div>
<div>

<?php
$title= "pen" ;
$penprice= 7 ;

?>
<form id="formpayment" action="<?php echo $urlname?>" method="post" >
<p style="color:blue; font:11px">
<input type="checkbox" id="check" name="kol" />Please add the eraser (Add 5$)
<br>
</p>
<table border="0" >
<tr>
<td><?php echo $title; ?>
</td>
<td ><input style="width: 60px; padding: 2px; border: 0px " class="txt" type="text" name="priceofpen" id="priceofpen" value="<?php echo $penprice ;?>
" readonly/>&nbsp$
</td>
<td>
</td>
</TR>
<tr>
<td><?php echo "Eraser price"; ?>
</td>
<td > <input style="width: 50px; padding: 2px; border: 0px " name="priceoferaser" class="txt" id="priceoferaser" value="0" readonly="readonly" /> &nbsp; &nbsp;$
</td>
<td>
</td>
</TR>
<tr>
<td colspan="3"> <hr />
</td>
</TR>
<tr id="summation">
<td> Total:
</td>
<td>
<input style="width: 60px; padding: 2px; border: 0px " type=number name="total" id="total" value="<?php echo $penprice;?>" readonly="readonly">$
</td>
<td>
</td>
</TR>
</table>
</p><br />
</form>
</div>
</div>
<script>
$('#check').on('change',function(){
var eraserprice = "5"

var c=parseFloat(eraserprice)+ parseFloat(<?php echo $penprice;?>);
if(this.checked)
$('#total').val( c )&& $('#priceoferaser').val( parseFloat(5000) ) )

else

$('#total').val( <?php echo $penprice;?>)&& $('#priceoferaser').val( parseFloat(0) )

})
</script>
</div>
</body>
</html>

最佳答案

您必须删除 .val( parseFloat(5000) ) 之后的最后一个“)”

<script>
$('#check').on('change',function(){
var eraserprice = "5"

var c=parseFloat(eraserprice)+ parseFloat(7);
if($(this).is(':checked'))
$('#total').val( c )&& $('#priceoferaser').val( parseFloat(5000) )

else

$('#total').val( 7)&& $('#priceoferaser').val( parseFloat(0) )

})
</script>

关于javascript - 复选框不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31808491/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com