Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery加载时获取默认检查值_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript jQuery加载时获取默认检查值

Javascript jQuery加载时获取默认检查值,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我有一个input radio列表,其中包含从数据库加载的自定义值。默认情况下,在加载窗口时,我选中了一项 所以,当我试图获取那个选中的值时,我得到了NULL,但选中的值是存在的 循环: <?php $first = true; ?> <?php foreach ($prices as $item): ?> <tr> <td><input type="radio" name="price" value="<?= $

我有一个
input radio
列表,其中包含从数据库加载的自定义
值。默认情况下,在加载窗口时,我选中了一项

所以,当我试图获取那个选中的值时,我得到了
NULL
,但选中的值是存在的

循环:

<?php $first = true; ?>
<?php foreach ($prices as $item): ?>
   <tr>
        <td><input type="radio" name="price" value="<?= $item['price'];?>"  class="price"  <?= $first ? 'checked' : '' ?>> </td>
        <td><input type="text" name="price" value=" <?= $item['price'];?>" class="price_field">&euro;</td>

    </tr>
<?php $first = false;?>
<?php endforeach; ?>

尝试
var price=$('.price:checked').val()。您需要.val()来获取jQuery中的值。既然可以通过PHP来实现,为什么还要使用jQuery呢?因为你是在页面加载时做的anyways@VincentDecaux你这样做可以解决我的问题@Nordenheim我需要jQuery bcs我在触发
change
事件时有其他ajax操作。@Zend是的,我理解,这很有意义,但在这个特殊的原因中,jQuery看起来像。。。我甚至不能称之为过度或不足。这是毫无意义的。PHP在生成页面时将变量插入到div中会做得很好,使用jQuery似乎可以在汽车上安装第二块挡风玻璃。更换车顶。
   $(window).on("load", function(){

        var price = $(".price");
        var total = $(".total");

        alert($(".price").val()); // null
     });