繁体   English   中英

使用jQuery更改输入类型数字值

[英]Change input type number value using jquery

所有其他属性更改似乎都可以在模式中正常运行。 模态中的评级按钮在加载时不会加载其值。 但检查元素似乎显示正确的额定值。 我是php和jquery的新手。 请原谅我上述代码中实现的愚蠢编程方法。 任何帮助将不胜感激。

HTML:

<div class="item" style="width: 400px; height: 230px">
  <!-- Link trigger modal -->
  <a data-img-url="upload/&lt;?php echo $row['image_name'] ?&gt;" data-toggle=
  "modal" href="#myModal" id="<?php echo $row['image_id'] ?>" onclick=
  "modalload(this.id, '&lt;?php echo $row['image_title'] ?&gt;' , '&lt;?php echo $row['image_description'] ?&gt;', &lt;?php echo $TAVG ?&gt; );"><img class="img-responsive carousal_scale"
  src="upload/%3C?php%20echo%20$row['image_name']%20?%3E"></a>

  <div class="carousel-caption">
    <p><?php echo $row['image_title'] ?></p>
  </div>
</div><!-- Modal -->

<div class="modal fade modal-dialog modal-content" id="myModal" tabindex="-1">
  <div class="modal-header">
    <button class="close" data-dismiss="modal" type=
    "button"><span>&times;</span><span class="sr-only">Close</span></button>

    <h2 class="modal-title" id="myModalLabel"></h2>
  </div>

  <div class="modal-body well">
    <img class="img-responsive carousal_scale" src=""> <input class="rating"
    data-size="xs" id="" max="5" min="0" onchange="test(this.id, this.value);"
    step="0.1" style="alignment-adjust: auto;" type="number" value="">
  </div>

  <div>
    <p style="text-align: center; font-size: 15px;"></p>
  </div>

  <div class="modal-footer">
    <button class="btn btn-default" data-dismiss="modal" type=
    "button">Close</button>
  </div>
</div>

JS:

 $(document).ready(function() {
   $(".rating-kv").rating();
 });

 function modalload(id, title, description, avg) {
   alert(avg);
   //    alert(description);     
   $('#myModal img').attr('src', $('#' + id).attr('data-img-url'));
   $('#myModal input').attr('value', avg);
   $('#myModal input').attr('id', id);
   $('#myModal h2').text(title);
   $('#myModal p').text(description);
 }

 function test(id, val) {
   var pic_id = id;
   var pic_val = val;
   $.ajax({
     type: 'POST',
     url: 'rating.php',
     data: {
       'pic_id': pic_id,
       'pic_val': pic_val
     },
   }).done(function(data) {
     //  alert(data);      
   });
 }

“模态中的评级按钮在加载时不会加载其值。” 您目前有你modalload()函数只能激活上的点击a标记,以便你的等级是不会得到它的价值/ ID填充上的负载,而是基于点击。

在您的modalload()函数中尝试此操作,

$('.rating').attr('value', avg);
$('.rating').attr('id', id);

另外,请注意,没有jQuery rating()函数,并且您的HTML中没有带有class rating-kv类的元素,因此下面的代码将无效。

$(".rating-kv").rating();

换句话说,您有很多不良的编码实践和不完整的代码。 您应该考虑修改现有内容,然后重新发布。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM