将通过ajax返回的HTML分配给任何HTML元素值 [英] Assigning HTML returned via ajax to any HTML element value
问题描述
我试图将从ajax返回的html分配给任何html元素的值.返回的html只包含22.5.因此,我想将此值分配给任何html元素值.
I have trying to assign the html returned from ajax to the value of any html element. The html returned only contains 22.5. So I want to assign this value to any html element value.
我正在使用的代码是:
$(document).ready(function(){
$("#coupon_btn").click(function(){
//alert("hello");
var coupon=$("#coupon").val();
var mem_price=$("#mem_price").val();
$.ajax({
type: 'POST',
url: 'http://localhost/freakinout1/paypal/coupon.php',
data: "coupon="+coupon+"&price="+mem_price,
cache: false,
success: function(html) {
var pay = $("#Payment_Amount").val();
$("#Payment_Amount").val() = html;
alert(pay);
//$('#search-results-container').html(html);
}
});
});
});
我在错误控制台中遇到的错误是左侧无效分配.
The error I am getting in error console is invalid assignment left hand side.
那么有人可以建议我我在做什么错吗?
So could someone suggest me what I am doing wrong?
推荐答案
val()
函数接受一个参数来设置调用它的对象的value
,将html
变量传递给val()
val()与诸如文本,复选框等输入类型的html元素一起使用.如果Payment_Amount为div或span,则需要使用html()
或text()
.
The val()
function accepts a parameter to set the value
of the object on which it is called, pass html
variable to val()
Note val() is used with html elements of input type like text, checkbox etc. If Payment_Amount is div or span then you will need to use html()
or text()
.
更改
$("#Payment_Amount").val() = html;
收件人
$("#Payment_Amount").val( html);
这篇关于将通过ajax返回的HTML分配给任何HTML元素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!