<!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>
1
A
回答
4
您的範圍x
是問題所在。 x
是jobID的本地。聲明x
以外的功能。
var x;
function jobID(form){
x = document.forms["JobIdForm"]["jobid"].value;
return false;
}
0
嘗試這樣:
JS
$(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>");
});
});
HTML作出上述工作所需:
<form name="JobIdForm" action="" method="post">
<label>Job ID <input type="text" name="jobid"></label>
<input type="submit" value="Submit">
</form>
+0
是的,j08691的關於x var範圍的帖子是爲什麼它不工作atm – DefyGravity
+0
我將發佈我的所有代碼,我可能在我的代碼中有另一個問題。 –
+0
我想避免這種情況,因爲我認爲我的代碼有點凌亂,無法在您的最後閱讀 –
相關問題
- 1. 使用jQuery刪除輸入並打印其價值
- 2. 以形式打印JS變量
- 3. 以文本形式打印Makefile變量
- 4. 變量賦值打印出輸出
- 5. 打印變量賦值作爲輸出
- 6. 用輸入值替換jQuery變量值
- 7. 讀取輸入字符並以圖形格式打印出現
- 8. 使用javascript保存本地以網頁形式輸入的特定變量值
- 9. 打印$ _POST變量名稱以及值
- 10. C++程序:使用輸入重定向打印梯形
- 11. 我可以使用用戶輸入按名稱打印變量嗎?
- 12. TCL EXPECT - 輸入密碼並打印到標準輸出並分配給變量
- 13. jQuery選擇:在形式指定輸入
- 14. JQuery獲得無線電輸入值,並打印它
- 15. 使用XML打印變量
- 16. 根據輸入+其他變量打印變量
- 17. CakePHP以表格形式輸入$變量
- 18. 通過用戶輸入獲取變量並使用變量形式爲URL
- 19. CoffeeScript的變量,以形成價值
- 20. HLA - 用stdout.put打印輸出變量
- 21. 輸入並指定要打印的字符以及要在每行上打印的字符數
- 22. 捕獲特定變量並打印其值
- 23. 複製圖形變量來打印圖形變量
- 24. 排序用戶輸入並打印它
- 25. nslog可以打印變量,但變量不具有值?
- 26. 如何指定輸入QMake INSTALLS變量?
- 27. 可以使用Django形式的可變數量輸入嗎?
- 28. 傳入指定類的成員變量
- 29. Var和使用Jquery的輸入變量
- 30. 變量設置爲隨機數,然後打印,然後輸入正確的輸入(可變)打印x
+1的範圍問題 – DefyGravity
這不起作用無論是。我的代碼必須有更多問題。但是,無論如何感謝修復。 –
感謝您的回答! –