简体   繁体   English

如何附加类型为“提交”的输入字段

[英]How to append a input field with the type 'submit'

I am currently looping through and appending the following information. 我目前正在遍历并附加以下信息。 It is appending fine but I am having problem when I append . 它追加很好,但是我追加时遇到问题。 By default it is coming as a text but I want it to be submit. 默认情况下,它将作为文本出现,但我希望将其提交。

When I try to append it as follows, it doesn't work. 当我尝试按如下所示添加它时,它不起作用。 (Blank screen) (黑屏)

 $("<input type="submit"/>",{
                text:"Paid"
            }).appendTo(wrap);

Please advice how I can append it aa type 'submit' . 请建议我如何将其添加为'submit'类型。 Thanks. 谢谢。

$.each(data,function(elem){
            var wrap = $("<div/>").attr('data-role', 'collapsible');
            identity.push(data[elem].id); 
            //Create the h1 and the other elements appending them to bills List
            $("<h1/>",{
                text:data[elem].reference
            }).appendTo(wrap);   
            $("<p/>",{
                text:"Account: "+ data[elem].account
            }).appendTo(wrap);        
            $("<p/>",{
                text:"Amount: "+ data[elem].amount
            }).appendTo(wrap);
            $("<input/>",{
                text:"Paid"
            }).appendTo(wrap);
            wrap.appendTo('#unpaidList');             
        })//end of for each loop

Try put the submit inside '' : 尝试将提交放入''

 $("<input type='submit'/>",{
                text:"Paid"
            }).appendTo(wrap);

Use single quotes when you are inside double quotes, because this way it's a simple syntax error. 当您在双引号内时,请使用单引号,因为这是一个简单的语法错误。

Your code should look like this: 您的代码应如下所示:

 $("<input type='submit'/>",{ text:"Paid" }).appendTo(wrap);

I suggest you to use the browser's JavaScript console, because that would surely indicate syntax errors immediately. 我建议您使用浏览器的JavaScript控制台,因为这肯定会立即指示语法错误。 Or even better if you use a tool such as FireBug . 如果使用诸如FireBug之类的工具,甚至会更好。

尝试使用此:

$('<input>').prop('type', 'text'): 

If it's a button, you may as well use a button tag... 如果是按钮,则最好使用按钮标签...

$('<button/>', {
      type: 'submit',
      text: 'Paid'
}).appendTo(wrap);

as an input tag: 作为输入标签:

$('<input/>', {
      type: 'submit',
      text: 'Paid'
}).appendTo(wrap);

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

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