简体   繁体   English

使用javascript填充输入字段的值

[英]Populate value of input field with javascript

I am able to populate paragraph using script below, but how can I populate input field value using this script? 我可以使用以下脚本填充段落,但是如何使用此脚本填充输入字段值? Any idea? 任何想法?

$(function check(){     
     $(document).ready(function() {
        $('#forma').submit(function(e){
        e.preventDefault();    
        $('.qty').each(function(){ 
           if($(this).val() != '0')
             {
                $('#output').text($('#output').text()+ ' ' + $(this).attr('name') + ' ' + $(this).val()+ ';' );
             }
          });
        });
     });
});

What you have to do is essentially the same as with the paragraph, ie you select the element by its id or class. 从本质上讲,您必须执行的操作与该段落相同,即,通过ID或类选择元素。 The difference is that for input fields you have to use .val("someValue") , whereas for paragraph you have to use .text("SomeText") just as you did. 区别在于,对于输入字段,您必须使用.val("someValue") ,而对于段落,则必须像以前一样使用.text("SomeText")

Hope this helps. 希望这可以帮助。

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

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