简体   繁体   English

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

[英]Change input type number value using jquery

All the other attribute changes seem to work fine inside the modal. 所有其他属性更改似乎都可以在模式中正常运行。 The rating button inside the modal doesn't load its value on loading. 模态中的评级按钮在加载时不会加载其值。 But the inspect element seems to display the proper rating value. 但检查元素似乎显示正确的额定值。 I am new to php and jquery. 我是php和jquery的新手。 Kindly excuse me from silly programming methodologies implemented in the above mentioned code. 请原谅我上述代码中实现的愚蠢编程方法。 Any help would be deeply appreciated. 任何帮助将不胜感激。

HTML : 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 : 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);      
   });
 }

"The rating button inside the modal doesn't load its value on loading." “模态中的评级按钮在加载时不会加载其值。” You currently have your modalload() function only activate on click of an a tag so your rating isn't going to get it's value/id populated on load, but rather on click. 您目前有你modalload()函数只能激活上的点击a标记,以便你的等级是不会得到它的价值/ ID填充上的负载,而是基于点击。

Try this instead inside your modalload() function, 在您的modalload()函数中尝试此操作,

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

Also, note that there is no jQuery rating() function, and that you have no element with the class rating-kv in your HTML, therefore the below code will do nothing. 另外,请注意,没有jQuery rating()函数,并且您的HTML中没有带有class rating-kv类的元素,因此下面的代码将无效。

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

In other words, you have a lot of bad coding practices and incomplete code. 换句话说,您有很多不良的编码实践和不完整的代码。 You should consider revising what you have and re posting it. 您应该考虑修改现有内容,然后重新发布。

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

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