I have form(<input type="button">
) in my html file, so for every input button I need to store those values in my json file/object after clicking Submit button, either using jquery or javascript or angularjs ? I have created Fiddle, but I am not sure where I am doing wrong ? Please help me this regard and thanks in advance.
我在我的html文件中有form(),所以对于每个输入按钮,我需要在点击Submit按钮后使用jquery或javascript或angularjs将这些值存储在我的json文件/对象中?我创造了小提琴,但我不确定我做错了什么?请帮助我这方面,并提前感谢。
1 个解决方案
#1
2
Not getting your exact requirement but I think you can do some thing like this:
没有得到你的确切要求,但我认为你可以这样做:
(function(){
var buttonValue = {};
$("#submit").click(function(){
$("input[type=button]").each(function($i){
var name =$(this).attr('name')
buttonValue[name]=$(this).val();
});
});
$("#seeData").click(function(){
console.log(buttonValue);
});
}())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='button' value='button1' class='button' name='firstButton'/>
<input type='button' value='button2' class='button' name='secondButton'/>
<input type='button' value='button3' class='button' name='thirdButton'/>
<input type='submit' value='submit' id='submit'>
<button id='seeData'>See Data In Console</button>
#1
2
Not getting your exact requirement but I think you can do some thing like this:
没有得到你的确切要求,但我认为你可以这样做:
(function(){
var buttonValue = {};
$("#submit").click(function(){
$("input[type=button]").each(function($i){
var name =$(this).attr('name')
buttonValue[name]=$(this).val();
});
});
$("#seeData").click(function(){
console.log(buttonValue);
});
}())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='button' value='button1' class='button' name='firstButton'/>
<input type='button' value='button2' class='button' name='secondButton'/>
<input type='button' value='button3' class='button' name='thirdButton'/>
<input type='submit' value='submit' id='submit'>
<button id='seeData'>See Data In Console</button>