在文本框中显示javascript var结果 [英] Show javascript var result in text box
本文介绍了在文本框中显示javascript var结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
D 耳朵,我需要JavaScript代码支持,此代码只使用span id我希望这个结果显示在html的隐藏输入中,任何人都可以帮助我。
html代码:
< 输入 type = text < span class =code-attribute> id = item-price >
javascript代码:
var basePrice = 0 ;
$( document )。ready( function (){
$( 。calculate)。change( function (){
newPrice = basePrice;
$( 。calculate option:选择)。each( function (){
newPrice + = $( this )。data(' price')
});
$ ( #item-price)。val(newPrice.toFixed( 2 ));
});
});
我的尝试:
i试图将.val更改为.html但没有任何事情发生。
解决方案
( document )。ready( function (){
( 。calculate)。change( function (){
newPrice = basePrice;
( 。calculate option:selected)。each( function (){
newPrice + =
Dears , i need support in JavaScript code, this code working with span id only i want this result showing in hidden input in html, can anybody help me.
html code :
<input type="text" id="item-price">
javascript code :
var basePrice = 0;
$(document).ready(function() {
$(".calculate").change(function() {
newPrice = basePrice;
$(".calculate option:selected").each(function() {
newPrice += $(this).data('price')
});
$("#item-price").val(newPrice.toFixed(2));
});
});
What I have tried:
i have tried to change .val to .html but nothing happend.
解决方案
(document).ready(function() {
(".calculate").change(function() { newPrice = basePrice;
(".calculate option:selected").each(function() { newPrice +=
这篇关于在文本框中显示javascript var结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文