输入值属性中的ajax响应

问题描述 投票:1回答:2

评论后的响应可以正常工作,但是我想执行类似$('#total_products').attr('value') = response;的操作,但这不起作用。为什么这不起作用,如何解决?

$(document).ready(function(){

  $.ajax({
    type : 'post',
    url : 'product_store.php',
    data : {
      total_products: "totalproducts"
    },
    success:function(response) {
      $('#total_products').attr('value') = response;
      /*document.getElementById("total_products").value=response;*/
    }
  });

})
jquery ajax jquery-selectors
2个回答
2
投票

使用此:

$('#total_products').attr('value',response);

jQuery attr文档:

http://api.jquery.com/attr/


6
投票

尽管以上解决方案是正确的,但在jQuery中执行此操作的正常方法是:


$('#total_products').val(response);
© www.soinside.com 2019 - 2024. All rights reserved.