简体   繁体   English

jQuery .html到.val

[英]Jquery .html to .val

I have this in a form: 我有这样的形式:

<span name="totalprice" id="totalprice">0</span>

and this jquery code: 和这个jQuery代码:

$('#totalprice').html((data * $('#numlic2').val() - (data * $('#numlic2').val() * $('#persent').val() / 100)).toFixed(2));

i recive data from php and replace it in the span field replacing the 0. I want to post the value of the totalprice but when i post it its blank so i think i have to assign the .html to .val am i wrong? 我从php获取数据,并在span字段中替换为0。我想发布totalprice的值,但是当我将其发布为空白时,我想我必须将.html分配给.val吗?我错了吗?

how can i do that in jquery? 我该怎么做在jQuery中?

You place 0 as default or initial value in span and you said you are getting blank in span then it mean something went wrong with you PHP code. 您将0设置为span默认值或初始值,并说span变得空白,这意味着您的PHP代码出现了问题。 Your PHP returns nothing. 您的PHP不返回任何内容。

jQuery html() is ok to replace the inner HTML of an element. jQuery html()可以替换元素的内部HTML。 You can use text() to change the text value of an element. 您可以使用text()更改元素的文本值。

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

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