Javascript 将变量指定给表单输入值,并使用jquery打印 var amount=新数组(); var x; 金额[0]=1; 函数jobID(表单){ x=document.forms[“JobIdForm”][“jobid”]。值; 返回false; } $(文档).ready(函数(){ jQuery(“”{ id:'盒子', 单击:函数(){ jQuery(“”{ id:'bob'+amount.length }).appendTo(“#滚动条”); jQuery(“”{ id:'bobb'+数量.长度 }).appendTo(“#滚动条”); jQuery(“”{ id:'Bobb'+amount.length }).appendTo(“#滚动条”); $('#bob'+amount.length).css('width','200px'); $('#bob'+amount.length).css('height','80px'); $('#bob'+amount.length).css('background-color','#f2f2'); $('#bob'+amount.length).css('border','3px纯黑'); $('#bob'+amount.length).css('margin-top','10px'); $('#bobb'+amount.length).append(x); $('#bobb'+amount.length).css('width','130px'); $('#bobb'+amount.length).css('height','80px'); $('#bobb'+amount.length).css('background-color','#f2f2'); $(“#bobb”+amount.length).css('border','3px纯黑'); $(“#bobb”+amount.length).css('margin-top','-86px'); $('#bobb'+amount.length).css('margin-left','220px'); $('#bobb'+amount.length).append('hello'); $('#bobb'+amount.length).css('width','300px'); $('#bobb'+amount.length).css('height','80px'); $('#bobb'+amount.length).css('background-color','#f2f2'); $(“#bobb”+amount.length).css('border','3px纯黑'); $('#bobb'+amount.length).css('margin-top','-86px'); $('#bobb'+amount.length).css('margin-left','370px'); $('#bobb'+amount.length).append('hello'); 金额【金额长度】=1; } }).附于(“主体”); $(“#框”)。追加(“全部提交”); }); 填表

Javascript 将变量指定给表单输入值,并使用jquery打印 var amount=新数组(); var x; 金额[0]=1; 函数jobID(表单){ x=document.forms[“JobIdForm”][“jobid”]。值; 返回false; } $(文档).ready(函数(){ jQuery(“”{ id:'盒子', 单击:函数(){ jQuery(“”{ id:'bob'+amount.length }).appendTo(“#滚动条”); jQuery(“”{ id:'bobb'+数量.长度 }).appendTo(“#滚动条”); jQuery(“”{ id:'Bobb'+amount.length }).appendTo(“#滚动条”); $('#bob'+amount.length).css('width','200px'); $('#bob'+amount.length).css('height','80px'); $('#bob'+amount.length).css('background-color','#f2f2'); $('#bob'+amount.length).css('border','3px纯黑'); $('#bob'+amount.length).css('margin-top','10px'); $('#bobb'+amount.length).append(x); $('#bobb'+amount.length).css('width','130px'); $('#bobb'+amount.length).css('height','80px'); $('#bobb'+amount.length).css('background-color','#f2f2'); $(“#bobb”+amount.length).css('border','3px纯黑'); $(“#bobb”+amount.length).css('margin-top','-86px'); $('#bobb'+amount.length).css('margin-left','220px'); $('#bobb'+amount.length).append('hello'); $('#bobb'+amount.length).css('width','300px'); $('#bobb'+amount.length).css('height','80px'); $('#bobb'+amount.length).css('background-color','#f2f2'); $(“#bobb”+amount.length).css('border','3px纯黑'); $('#bobb'+amount.length).css('margin-top','-86px'); $('#bobb'+amount.length).css('margin-left','370px'); $('#bobb'+amount.length).append('hello'); 金额【金额长度】=1; } }).附于(“主体”); $(“#框”)。追加(“全部提交”); }); 填表,javascript,jquery,html,forms,input,Javascript,Jquery,Html,Forms,Input,工作ID 日期 描述 工作ID 您的x范围就是问题所在x是jobID的本地代码。在函数外部声明x <!DOCTYPE html> <html> <head> <link rel="stylesheet" href = "Jquery.css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></scr

工作ID

日期

描述

工作ID
您的
x
范围就是问题所在<代码>x是jobID的本地代码。在函数外部声明
x

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href = "Jquery.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>

        var amount = new Array();
        var x;
        amount[0] = 1;

        function jobID(form){

            x = document.forms["JobIdForm"]["jobid"].value;
            return false;


        }

        $(document).ready(function(){
            jQuery('<div/>', {
                id: 'box',


                click: function(){
                    jQuery('<div/>', {
                        id: 'bob'+amount.length
                    }).appendTo('#scroller');
                    jQuery('<div/>', {
                        id: 'bobb'+amount.length
                    }).appendTo('#scroller');
                    jQuery('<div/>', {
                        id: 'bobbb'+amount.length
                    }).appendTo('#scroller');
                    $('#bob'+amount.length).css('width', '200px');
                    $('#bob'+amount.length).css('height', '80px');
                    $('#bob'+amount.length).css('background-color', '#F2F2F2');
                    $('#bob'+amount.length).css('border', '3px solid black');
                    $('#bob'+amount.length).css('margin-top', '10px');
                    $('#bobb'+amount.length).append(x);


                    $('#bobb'+amount.length).css('width', '130px');
                    $('#bobb'+amount.length).css('height', '80px');
                    $('#bobb'+amount.length).css('background-color', '#F2F2F2');
                    $('#bobb'+amount.length).css('border', '3px solid black');
                    $('#bobb'+amount.length).css('margin-top', '-86px');
                    $('#bobb'+amount.length).css('margin-left', '220px');
                    $('#bobb'+amount.length).append('hello');

                    $('#bobbb'+amount.length).css('width', '300px');
                    $('#bobbb'+amount.length).css('height', '80px');
                    $('#bobbb'+amount.length).css('background-color', '#F2F2F2');
                    $('#bobbb'+amount.length).css('border', '3px solid black');
                    $('#bobbb'+amount.length).css('margin-top', '-86px');
                    $('#bobbb'+amount.length).css('margin-left', '370px');
                    $('#bobbb'+amount.length).append('hello');

                    amount[amount.length] = 1;

                }


            }).appendTo('body');
            $('#box').append("Submit All");
        });
    </script>
</head>

<body>

    <header>
        <h1>Fill out Forms</h1>
    </header>
    <section>
        <div id="keys">
            <div id ="job">
                <p>Job ID</p>
            </div>
            <div id="date">
                <p>Date</p>
            </div>
            <div id="desc">
                <p>Description</p>
            </div>
        </div>
        <div id = "scroller" style="width: 700px; height: 400px; overflow-y: scroll;">

        </div>

        <form name="JobIdForm" action="" onsubmit="return jobID(this)" method="post">


            Job ID <input type="text" name="jobid">
            <input type="submit" value="Submit">    




        </form>
    </section>


</body>
</html>

您的
x
范围就是问题所在<代码>x是jobID的本地代码。在函数外部声明
x

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href = "Jquery.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>

        var amount = new Array();
        var x;
        amount[0] = 1;

        function jobID(form){

            x = document.forms["JobIdForm"]["jobid"].value;
            return false;


        }

        $(document).ready(function(){
            jQuery('<div/>', {
                id: 'box',


                click: function(){
                    jQuery('<div/>', {
                        id: 'bob'+amount.length
                    }).appendTo('#scroller');
                    jQuery('<div/>', {
                        id: 'bobb'+amount.length
                    }).appendTo('#scroller');
                    jQuery('<div/>', {
                        id: 'bobbb'+amount.length
                    }).appendTo('#scroller');
                    $('#bob'+amount.length).css('width', '200px');
                    $('#bob'+amount.length).css('height', '80px');
                    $('#bob'+amount.length).css('background-color', '#F2F2F2');
                    $('#bob'+amount.length).css('border', '3px solid black');
                    $('#bob'+amount.length).css('margin-top', '10px');
                    $('#bobb'+amount.length).append(x);


                    $('#bobb'+amount.length).css('width', '130px');
                    $('#bobb'+amount.length).css('height', '80px');
                    $('#bobb'+amount.length).css('background-color', '#F2F2F2');
                    $('#bobb'+amount.length).css('border', '3px solid black');
                    $('#bobb'+amount.length).css('margin-top', '-86px');
                    $('#bobb'+amount.length).css('margin-left', '220px');
                    $('#bobb'+amount.length).append('hello');

                    $('#bobbb'+amount.length).css('width', '300px');
                    $('#bobbb'+amount.length).css('height', '80px');
                    $('#bobbb'+amount.length).css('background-color', '#F2F2F2');
                    $('#bobbb'+amount.length).css('border', '3px solid black');
                    $('#bobbb'+amount.length).css('margin-top', '-86px');
                    $('#bobbb'+amount.length).css('margin-left', '370px');
                    $('#bobbb'+amount.length).append('hello');

                    amount[amount.length] = 1;

                }


            }).appendTo('body');
            $('#box').append("Submit All");
        });
    </script>
</head>

<body>

    <header>
        <h1>Fill out Forms</h1>
    </header>
    <section>
        <div id="keys">
            <div id ="job">
                <p>Job ID</p>
            </div>
            <div id="date">
                <p>Date</p>
            </div>
            <div id="desc">
                <p>Description</p>
            </div>
        </div>
        <div id = "scroller" style="width: 700px; height: 400px; overflow-y: scroll;">

        </div>

        <form name="JobIdForm" action="" onsubmit="return jobID(this)" method="post">


            Job ID <input type="text" name="jobid">
            <input type="submit" value="Submit">    




        </form>
    </section>


</body>
</html>

试着这样做:

js
$(function(){//相当于$(document).read(function(){});
//您现在正在提交时运行“joID(form)”,但是要在html中编写/调用它。我尽量避免这样做。
$(“form[name='JobIdForm'])。提交(函数(事件){
//我没有看到实际的form[action]值,所以我使用default()来调用它
event.preventDefault();
//我们需要bob中的值,因此我让jQuery创建一个并在元素标记之间抛出输入值
$(“#bob”).append($(“”+$(this.find)(“input[name='jobid']).val()+”);
});
});
实现上述功能所需的html:

工作ID

尝试以下方法:

js
$(function(){//相当于$(document).read(function(){});
//您现在正在提交时运行“joID(form)”,但是要在html中编写/调用它。我尽量避免这样做。
$(“form[name='JobIdForm'])。提交(函数(事件){
//我没有看到实际的form[action]值,所以我使用default()来调用它
event.preventDefault();
//我们需要bob中的值,因此我让jQuery创建一个并在元素标记之间抛出输入值
$(“#bob”).append($(“”+$(this.find)(“input[name='jobid']).val()+”);
});
});
实现上述功能所需的html:

工作ID

是的,j08691关于x var作用域的帖子是它不起作用的原因。atmI将发布我的所有代码,我的代码中可能还有另一个问题。我想避免这一点,因为我认为我的代码在你端阅读时有点凌乱。不要介意作用域问题修复了问题,我从未注意到,因为我在运行之前没有保存我的工作。新手mistake.yes,j08691关于x var作用域的帖子是它不起作用的原因atmI将发布我的所有代码,我的代码中可能还有另一个问题。我想避免这个问题,因为我认为我的代码在你端读起来有点凌乱。别介意作用域问题解决了这个问题,我从未注意到,因为我在运行之前没有保存我的工作。新手错误。这也不起作用。我的代码肯定有更多问题。但无论如何,谢谢你的修复。谢谢你的回答!这也不起作用。我的代码肯定有更多问题。但无论如何,谢谢你的修复。谢谢你的回答!
 $(function(){  //equivalent to $(document).read(function(){});
    //you are running "joID(form)" on submit now, but have it written/called right in the html.  i try to avoid that.
      $("form[name='JobIdForm']").submit(function(event){
//i did not see an actual form[action] value, so I preventDefault() to call that out
        event.preventDefault();
//we want the value in bob, so I have jQuery create a <div> and throw the input value between the element tags
        $("#bob").append($("<div>"+$(this).find("input[name='jobid']").val()+"</div>");
      });

    });
<form name="JobIdForm" action="" method="post">       
    <label>Job ID <input type="text" name="jobid"></label>
    <input type="submit" value="Submit">    

</form>